Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING JAVA Also using Eclipse IDE if available. If not, any IDE is fine In this assignment, you will create four classes, a base class,

USING JAVA

Also using Eclipse IDE if available. If not, any IDE is fine

In this assignment, you will create four classes, a base class, two child classes and a user class. The base class will be a BasketballPlayer class. The two child classes will be CollegeBasketballPlayer and ProBasketballPlayer. The BasketballPlayer class will have instance data of name, position, team (Strings), height, weight, agility, speed, ballHandling (ints) and all should be declared as protected instead of private. You will have 3 constructors, a 0 parameter constructor (all instance data are initialized to unknown or 0), a 3-parameter constructor which receives the 3 Strings and assigns the 3 String instance data to them and 0 to all int instance data, and one which receives a parameter for each instance data and assigns them all appropriately. Also create accessors for all instance data and a toString which will return at least the name, position, team and the value for a method you will write called getValue. The getValue method will test various instance data and return an int using nested if-else logic based on the table below. All methods should be public.

image text in transcribed

NOTE: empty other conditions mean any values, these would be used in else clauses.

Compile this class before continuing, as you cannot implement the child classes without this one being compiled. Fix any syntax errors

As a second part, implement a CollegeBasketballPlayer to extend BasketballPlayer. It will have two instance data, eligibilityRemaining (int) and role (String). Note: these can be protected or private as we do not plan to extend this class. Have 3 different constructors, a 0 param constructor, a 3 param constructor (name, position, team) and a constructor that receives all params. Use super(); for the 0 param constructor, super(); for the other two constructors, passing the appropriate parameters. Assign eligibilityRemaining and role to either 4 and bench for the 0 and 3 parameter constructors or the proper params for the third constructor. Add accessors for these two instance data a new toString method which return super.toString() + \t + where is at least the role of this player (and the eligibilityRemaining if desired). Finally, add a method called draftable which returns a boolean based on the following logic:

A player is draftable if he/she is a starter (role) whose value (as obtained by super.getValue()) > 4 or is a bench player (role) whose value >= 8.

Compile this class and fix any errors.

Implement ProBasketballPlayer by extending BasketballPlayer. Add 2 new instance data: yearsInLeague (int) and role (String). Add 3 constructors similar to what you had for CollegeBasketballPlayer. For the first two constructors, yearsInLeague should be initialized to 0 and role to bench. Add accessors for the two new instance data and a toString which will add to BasketballPlayers toString both yearsInLeague and role. Finally, implement a method called newContractValue which returns an int value based on the logic in the following table.

image text in transcribed

Again, empty entries in the table mean any value. NOTE: because of the logic here, you may need to add else return 0; at the end of your nested if-else statement to satisfy the Java compiler.

Compile this class and fix any errors

Finally, create a user class with an empty main method, called assignment3. On elearning, some java code is attached, which is a test driver for your code. Copy it into this user class to be the main method. In the code, you will see three variables, bp1, bp2 and bp3, declared as a BasketballPlayer, CollegeBasketballPlayer and ProBasketballPlayer respectively. Notice that bp1 could take on an object of BasketballPlayer, CollegeBasketballPlayer or ProBasketballPlayer but bp2 and bp3 are limited to just their declared type. The code then performs various instantiations and message passing on bp1, bp2 and bp3. You will notice some of the instructions have syntax errors. Before trying to compile the program, comment out the instructions that have syntax errors and add in comments next to those instructions the reason for the errors.

Examine the source code and add comments whenever a method is being invoked via dynamic type binding. Finally, compile and run your program and capture the output. Copy the output to a file, by copy-paste, then create a text file under your eclipse project called output.txt, the paste the copied content to it.

ATTACHED IS THE DRIVER CODE

image text in transcribed

sition Other conditions Value enter height 82, weight between 220 and 250, ball handling> Center Center height80, weight between 210 and 260, ball handling>5 8 height 80, ball handling4 Centerheight-78, agility>7 Center height 78 Centerheight 76, agility>5 Center Forward height80 and either agility >8 or speed>7 Forward hei Forwardh 5 Forward height76, speed4 Forwardheight75 and either agility>3 or speed>3 10 ght 78, agility> 6, speed>5 height-77, agility> Frward height-74 Forward Guardheight Guard 78, ball handling>7 and either agility or speed>7 10 height >= 76, ball handling > 7 and either agility or speed > 618 Guard Guard height-74, ball handling> 5, agility> 5, speed 6 ball handling6, agiliy 6, speed>5 Guard ball handling> 4, agility>4 Guard Value (using getValueYears in League Role Return value >= 10 Starter Starter Starter Starter Starter Starter Bench Bench Bench Bench Bench 12,000,000 10,000,000 8,000,000 6,000,000 2,000,000 1,000,000 7,500,000 5,000,000 4,500,00 2,000,000 500,000 -5 5 10 10 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

please try to give correct answer 9 3 . .

Answered: 1 week ago