Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Basketball Player Write a Java class called BasketballPlayer that has three instance variables: - name - The player's name (type is String) - totalGamesPlayed -

image text in transcribed
image text in transcribed
Basketball Player Write a Java class called BasketballPlayer that has three instance variables: - name - The player's name (type is String) - totalGamesPlayed - The number of games in which this player has played this season (type is int) - totalPointsScored - The total number of points this player has scored for the entire season (type is int) Include in the class: - a constructor that accepts all three of those values - a standard accessor method (getter) for each of the instance variables - a toString( ) method, which should work in the same way as the toString( ) method for the Product class discussed in Module 4 . In other words, the result returned by this method should be in this format (but with your own test values, as described below): Basketbal1player [name=Andrew, totalGames P1 layed =4, totalpointsscored =14 ] - an addGameResult ( ) method. This method has one parameter - the number of points this player scored in one game. This value is used to update totalPointsScored, and this method also adds one to totalGamesPlayed. - a getPointsPerGame() ) method. This method calculates and returns the average points this player has scored per game this season. Be sure to allow for significant digits to the right of the decimal point. (We have not yet seen the Java capabilities we need to handle the case where the number of games played is zero, so for this method you can assume the player has played in at least one game. This avoids the problem of dividing by zero.) That's a total of six methods, plus the constructor. Also write a second class called BasketballPlayerTest, which includes a main( ) method. Use this class to test your BasketballPlayer class as follows: as described below): BasketballPlayer [name=Andrew, totalGamesPlayed =4, totalpointsscored =14 ] - an addGameResult( ) method. This method has one parameter - the number of points this player scored in one game. This value is used to update totalPointsScored, and this method also adds one to totalGamesPlayed. - a getPointsPerGame( ) method. This method calculates and returns the average points this player has scored per game this season. Be sure to allow for significant digits to the right of the decimal point. (We have not yet seen the Java capabilities we need to handle the case where the number of games played is zero, so for this method you can assume the player has played in at least one game. This avoids the problem of dividing by zero.) That's a total of six methods, plus the constructor. Also write a second class called BasketballPlayerTest, which includes a main( ) method. Use this class to test your BasketballPlayer class as follows: - Create two BasketballPlayer objects with data of your own choosing. There is no need for user input - simply use constant values in creating the objects. - Call toString( ) for both objects and print the results. - Call the addGameResult() method for each object, with data of your own choosing. Then use toString( ) again to show that addGameResult() worked properly in both cases. - Call getPointsPerGame( ) and the three accessor methods for both objects, printing the results. - Label all printed results so the meaning is clear. Include blank lines to help with readability

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

Step: 3

blur-text-image

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

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

More Books

Students also viewed these Databases questions

Question

Please two examples of variable cost and fixed cost?

Answered: 1 week ago

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago