Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework Assignment 7 STEP 1 Create Superclass and Subclasses Create an Eclipse project named JohnDoeHw7, and use the default package, i.e., no package name should

Homework Assignment 7

STEP 1 Create Superclass and Subclasses

Create an Eclipse project named JohnDoeHw7, and use the default package, i.e., no package name should be provided. Then inside this project, create the parent class (superclass) Player as specified in the table below. Save it in a file Player.java.

Also create the three child classes (subclasses) shown below. Save each class in a separate file BaseballPlayer.java, FootballPlayer.java, and BasketballPlayer.java.

Class names

Player

(superclass)

BaseballPlayer (subclass of Player)

FootballPlayer

(subclass of Player)

BasketballPlayer (subclass of Player)

private data

id

number of hits

number of yards

number of shots made

player name

number of times at bat

number of rushes

number of shots attempted

team name

position

salary

commission rate

public methods

constructors

constructors

constructors

constructors

getters

getters

getters

getters

setters

setters

setters

setters

calculate comission

calculate statistics

calculate statistics

calculate statistics

determine status

determine status

determine status

Detail specifications:

In class Player:

  • id is of int type; player name, team name, position is of String type; salary, commission rate is of double type.
  • There should be two constructors, one is the default constructor with no parameter, and the other has all six parameters to initialize the six private data fields, respectively.
  • There should be a public getter and setter for each of the six private data fields.
  • There is one effector method to calculate the commission by multiplying the salary with the commission rate. This method return a double type.

In class BaseballPlayer:

  • The two private data fields are int type.
  • There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
  • There should be a public getter and setter for each of the two private data fields.
  • There are two effector methods:
    • calculate statistics : calculate the players batting average by dividing the number of hits by the number of times at bats, it should return a double type
    • determine status : boolean return type. If the batting average is more than 0.25, return true; o/w return false

In class FootballPlayer:

  • The two private data fields are int type.
  • There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
  • There should be a public getter and setter for each of the two private data fields.
  • There are two effector methods:
    • calculate statistics : Calculate the players rushing average by dividing the number of yards by the number of rushes , it should return a double type
    • determine status : boolean return type. If the rushing average is more than 3.5, return true; o/w return false

In class BasketballPlayer:

  • The two private data fields are int type.
  • There should be two constructors, one is the default constructor with no parameter, and the other has all eight parameters to initialize the six inherited data fields plus the two private data fields, respectively.
  • There should be a public getter and setter for each of the two private data fields.
  • There are two effector methods:
    • calculate statistics : Calculate the players shot percentage by dividing the number of shots made by the number of shots attempted , it should return a double type
    • determine status : boolean return type. If the shot percentage is more than 0.32, return true; o/w return false

The three constant values mentioned in the determine status method as thresholds should be defined as public static final variable in the three subclasses, respectively.

DO NOT ADD or DELETE any method from the requirements above, and you should strictly follow the requriements.

STEP 2 Create UML class diagram for the Player class family

Draw the UML class diagram for Player class and its three subclasses. Once it is finished, you need to export the UML class diagram as an jpg image file with name JohnDoePlayer.jpg, and replace JohnDoe with your first and last name.

STEP 3 Create an application class that uses the Player class family

In the same Eclipse project, create a new class file named JohnDoeHw7.java.

This application file has the main method, and inside the main method, it will create two instances of BaseballPlayer, two instances of FootballPlayer, and two instances of BasketballPlayer.

For each instance, you should use the constructor with 8 parameters, and then plug in all 8 parameters directly in the constructor.

You can use arbitrary values for the 8 parameters in each instance, as long as they are reasonable, for example, in basketball player, number of shots made should be less than number of shots attempted.

Then for each player instance, you need to output the six inherited data fields from Player class, and its commissions, then output the two private date fields, and then the statistics of this player, and the keeping status of this player: true of false. An example output for a football player is as below:

player id: 20

name: Barry Sanders

team: OSU

position: running back

salary: 1000000.00

commission rate: 0.02

commission: 20000.00

number of yards: 2850

number of rushes: 373

statistics: 7.6

keeping status: true

The output precision requirement: for monetary items, two digits after the decimal point; for statistics, one digit after the decimal point. Use System.out.printf() method to format the String type and boolean type (%s), double type(%f), and int type (%d) output items, with format specifier %s, %f, and %d, respectively. For double type, you need to specify the number of precisions after the decimal point.

Generate a simialr output as above for all six players. When you hardcode parameters to initialize the six playes, you can carefully design the parameters so that in each sport category, one player has keeping status as true, and the other player has it as false.

STEP 4 CHECK YOUR WORK FOR ADHERENCE TO PROGRAM SPECIFICATIONS

NOTE ADDITIONAL SPECIFICATIONS!!

  • You do NOT need to use any array in this homework.
  • The names of the classes must be exactly as stated in the table in page 1 of this document.
  • You can not CHANGE, ADD or DELETE any instance variable or method to the Player class and its subclasses. However, inside each method, you have the freedom to use and name any local variable that you need. Also in the main method of the application class, you have the freedom to name and use any local variable.
  • For class Player and its subclasses, you must provide a constructor without arguments and a constructor with a full list of arguments to initialize all inherited data fields (if applicable), and all private data fields.
  • In main method, you must use constructors with actual parameters to create the required six objects, by hardcoding the arguments in the contructors. NO USER INPUT is needed in this homework!
  • For the determine statistics method in each subclass, the division should happen between two int type variables, and the result should be double. How do you achieve that? Hint: in the division statement, type converting the dividend from int to double will yiled a double result, such as (double) dividend / divisor
  • Except for the three threshold values in the three subclasses, all class data must be private, and you must provide public getters and setters for each private instance data.
  • The methods to calculate statistics must have the exactly SAME name in all classes.
  • The methods to determine the players status must have exactly the SAME name in all classes and must all return a boolean.
  • You do NOT need to use any abstract class or abstract method in this homework.
  • Put each class in a separate file Player.java, BasketballPlayer.java, FootballPlayer.java,.java, BaseballPlayer.java, and JohnDoeHw7.java(for application program that has the main method).

What and where to submit: you need to zip these files together, and name the zip file JohnDoeHw7.zip:

  • Player.java
  • BaseballPlayer.java
  • FootballPlayer.java
  • BasketballPlayer.java
  • JohnDoeHw7.java
  • JohnDoePlayer.jpg (this is the exported image file of the UML class diagram for class Player and its subclasses

My output terminal however looks like this: Baseball Player: ID: 15 Player Name: Whit Merrifield Team Name: KC Position: Second Base Salary: $ 4062500.00 Commission Rate: 0.56 Number Of Hits: 70 Number Of Times At Bat: 248 Batting Average: 0.00 Status: false

Baseball Player: ID: 79 Player Name: Jose Abreu Team Name: CHW Position: First Base Salary: $ 1666666.00 Commission Rate: 1.05 Number Of Hits: 76 Number Of Times At Bat: 240 Batting Average: 0.00 Status: false

Football Player: ID: 20 Player Name: Barry Sanders Team Name: OSU Position: Running Back Salary: $ 1000000.00 Commission Rate: 0.02 Number Of Yards: 2850 Number Of Rushes: 373 Average Yards: 7.00 Status: true

Football Player: ID: 24 Player Name: Nick Chubb Team Name: UGA Position: Running Back Salary: $ 1342381.00 Commission Rate: 0.60 Number Of Yards: 1345 Number Of Rushes: 223 Average Yards: 6.00 Status: true

Basketball Player: ID: 12 Player Name: Steven Adams Team Name: NOP Position: Center Salary: $ 17073171.00 Commission Rate: 1.00 Number Of Shots Made: 4 Number Of Shots Attempted: 6 Shot Average: 0.00 Status: false

Basketball Player: ID: 33 Player Name: Ryan Anderson Team Name: HOU Position: Power Forward Salary: $ 5214584.00 Commission Rate: 1.00 Number Of Shots Made: 1 Number Of Shots Attempted: 4 Shot Average: 0.00 Status: false

How do I fix the Batting Shot, and Yard averages? Also If UML class diagrams could be provided that would be very helpful. Thank you!

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

Are you exposed to any hazards or unusual working conditions?

Answered: 1 week ago