Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA, Write a class encapsulating the concept of statistics for a baseball te

ID: 3546400 • Letter: I

Question

In JAVA, Write a class encapsulating the concept of statistics for a baseball team, which has the following attributes: a number of players, a list of number of                 hits for each player, a list of number of at-bats for each player.
                Needs to include:
                - A constructor with 2 equal-lenght arrays - number of hits per player and nujmber of at bats per player.
                - Accessors, mutators, toString and equals methods
                - Generate and return an array of batting averages based on attributes given
                - Calculate and return total number of hits for the team
                - Calculate and return number of players with batting averages over .300
                - a method returning an array holding the number of hits in ascending order


Whats the main method for this

Explanation / Answer

import java.text.DecimalFormat;

02

public class Baseball {

03

04

05

public static void main(String[] args)

06

{

07

int [] teamHits= {20,33,35,40,25,15,21,24,36};

08

int [] teamAtBats= {100,99,101,100,99,7575,88,90,103};

09

int players=9;

10

  

11

//instantiate an object calling the overloaded constructor

12

BaseballClient bStat1= new BaseballClient(teamHits,teamAtBats, players);

13

  

14

//call toString

15

System.out.print("bStat1: " + bStat1);

16

17

  

18

//instantiate identical object

19

BaseballClient bStat2= new BaseballClient(teamHits, teamAtBats, players);

20

  

21

  

22

//calling accessors

23

System.out.println("bStat2 " + bStat2);

24

25

int [] x= bStat1.getAtBats();

26

for(int i=0;i<x.length;i++)

27

System.out.print(x[i] + " ");

28

System.out.println();

29

30

  

31

//test equals

32

if(bStat1.equals(bStat2))

33

System.out.println("Equal");

34

else

35

System.out.println("Not equal");

36

37

  

38

  

39

//change some data-call mutator

40

System.out.println(" Setting Stat1 and Stat2 arrays to teamHits");

41

bStat1.setHits(teamHits);

42

bStat2.setHits(teamHits);

43

44

System.out.println(bStat1);

45

System.out.println("Comparing Stat1 and Stat2 for equality");

46

47

48

//Test average>100

49

DecimalFormat average= new DecimalFormat("0.00");

50

System.out.println("The average score is" +

51

average.format(bStat1.battingAverages()));

52

53

  

54

  

55

  

56

//sorting

57

System.out.println(" Sorted Score");

58

x= bStat1.sortedHits();

59

for(int i=0;i<x.length;i++)

60

System.out.print(x[i] + " ");

61

System.out.println();

62

63

64

65

}

66

67

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote