Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Looking for some direction with this lab A Player class. A Player has instance variables for name and height . (Keep height in inches; use

Looking for some direction with this lab

A Player class. A Player has

  • instance variables for name and height. (Keep height in inches; use an int.)
  • overloaded constructors
    • A constructor that takes name and height parameters
    • A no-argument constructor
  • getters and setters for name and height
  • a String toString() method that returns a player's data as a String object

A Team class. A Team has

  • an instance variable that is an array of the team's players (i.e., Player[] myTeam)
  • an instance variable that indicates the "next open" position of the team array. You may assume that no more than 3 players will be added to a team, but a team might have less than 3 players.
  • a no-argument constructor that initializes the player array
  • a method void add(Player player) that adds a player to the team
  • a method Player[] getCurrentTeamMembers() that returns a player array of all the players currently on the team (note that the team may not have a full roster when this method is called. You should return an array with no "empty" slots.)
  • a methodint averageHeight()that returns the average height (in inches) of all the players currently on the team. Your code should handle a team with no members.
  • aString toString()method that returns the number of players currently on the team, and their names and heights

A Game class. A Game class has

  • a private static Scanner class variable for reading user input from the keyboard
  • a methodprivate static Team fillRoster()that uses the Scanner to query the user for all of the players on a Team.
  • amainmethod. The main method
    • has two Team variables, home and visitor
    • usesfillRoster to create the Team object and its associated Player objects for the home team
    • usesfillRoster to create the Team object and its associated Player objects for the visting team
    • prints a message identifying the team (home or visitor) that has the taller average height
    • prints the taller team's roster
    • prints the shorter team's roster

A sample execution of the program is attached below.

Enter the home team

Enter team member 1:

Name: Aaron

Height: 73

Enter team member 2:

Name: Abe

Height: 78

Enter team member 3:

Name: Andrew

Height: 80

Enter the visiting team

Enter team member 1:

Name: Bob

Height: 70

Enter team member 2:

Name: Ben

Height: 81

Enter team member 3:

Name: Bill

Height: 78

The home team is taller Taller team roster: Team{numPlayers=3, members=[Player{name='Aaron', height=73}, Player{name='Abe', height=78}, Player{name='Andrew', height=80}]}

Shorter team roster: Team{numPlayers=3, members=[Player{name='Bob', height=70}, Player{name='Ben', height=81}, Player{name='Bill', height=78}]}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions