Question
Question #1 This is a long assignment, so I divided into two question. Because chegg won't let me upload it in one question because it
Question #1
This is a long assignment, so I divided into two question. Because chegg won't let me upload it in one question because it was too long. I know it's very much of a hassle; however, I really need this question's solution. I will leave the link to the 2nd question that is connected to this question. The output I need written below will need both questions I posted. Please help.
https://www.chegg.com/homework-help/questions-and-answers/question-s-connected-first-question-posted-https-wwwcheggcom-homework-help-questions-answe-q70149761
This is the link for the 2nd question.
Thank you.
Inheritance - Creating a Multilevel Hierarchy
In this lab you will start use Inheritance to create a Creating a Multilevel Hierarchy.
Deliverable
A zipped NetBeans project with 2 classes
- app
- ZipCode
- Address
- Person
- Player
- FootballPlayer
- SoccerPlayer
Classes
The Person Class
- Uses encapsulation
- Attributes
- private String name
- private Address address
- Constructors
- one constructor with no input parameters
- since it doesn't receive any input values, you need to use the default values below:
- name - "John Doe"
- address - use the default constructor of Address
- since it doesn't receive any input values, you need to use the default values below:
- one constructor with all (two) parameters
- one input parameter for each attribute
- one constructor with no input parameters
- Methods
- public String toString()
- returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
- toString() is a special method, you will learn more about it in the next lessons
- it needs to be public
- it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
- Get and Set methods
- public int getName()
- public void setName(String name)
- public Address getAddress()
- public void setAddress(Address address)
- public String toString()
The Player Class (with updates from the last lab)
- Player is a Person with some extra attributes
- Uses encapsulation
- Player now is an abstract class because it has an abstract method
- public double getRatings( );
- an abstract method is an incomplete method that has to be implemented by the subclasses.
- public double getRatings( );
- Attributes
- private int number
- private String sports
- private gamesPlayed
- Constructors
- one constructor with no input parameters
- since it doesn't receive any input values, you need to use the default values below:
- number - 0
- sports - "none"
- gamesPlayed - 0
- since it doesn't receive any input values, you need to use the default values below:
- one constructor with all (three) parameters
- one input parameter for each attribute
- one constructor with no input parameters
- Methods
- public String toString()
- returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
- toString() is a special method, you will learn more about it in the next lessons
- it needs to be public
- it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
- Get and Set methods
- public int getNumber()
- public void setNumber(int number)
- public String getSports()
- public void setSports(String sports)
- public int getGamesPlayed()
- public void setGamesPlayed(int gamesPlayed)
- public abstract getRatings();
- public String toString()
The SoccerPlayer Class
- SoccerPlayer is a Player with some extra attributes
- Uses encapsulation
- SoccerPlayer will implement the method getRatings (an abstract method from the superclass Player)
- toString has to include the result of getRatings() too
- Attributes
- private int goals
- private int yellowCards
- Constructors
- one constructor with no input parameters
- since it doesn't receive any input values, you need to use the default values below:
- goals - 0
- yellowCards - 0
- since it doesn't receive any input values, you need to use the default values below:
- one constructor with all (two) parameters
- one input parameter for each attribute
- one constructor with no input parameters
- Methods
- public String toString()
- returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
- toString() is a special method, you will learn more about it in the next lessons
- it needs to be public
- it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
- should also include the value of getRatings() in the string
- Get and Set methods
- public int getGoals()
- public void setGoals(int goals)
- public int getYellowCards()
- public void setYellowCards(int yellowCards)
- public double getRatings()
- calculate and return the rates using this formula:
- (double) (goals - yellowCards)/gamesPlayed
- the (double) is called casting, forcing the expression that comes afterwards to become a double.
- it is necessary to avoid getting 0 as a result because of the precision loss in the division by integers
- if goals or gamesPlayed is 0, return 0 (you need to do this test to avoid the application crashing in case one of them is 0)
- (double) (goals - yellowCards)/gamesPlayed
- calculate and return the rates using this formula:
- public String toString()
The FootballPlayer Class
- FootballPlayer is a Player with some extra attributes
- Uses encapsulation
- FootballPlayer will implement the method getRatings (an abstract method from the superclass Player)
- toString has to include the result of getRatings() too
- Attributes
- private int yards
- private int minutesPlayed
- Constructors
- one constructor with no input parameters
- since it doesn't receive any input values, you need to use the default values below:
- yards - 0
- minutesPlayed - 0
- since it doesn't receive any input values, you need to use the default values below:
- one constructor with all (two) parameters
- one input parameter for each attribute
- one constructor with no input parameters
- Methods
- public String toString()
- returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
- toString() is a special method, you will learn more about it in the next lessons
- it needs to be public
- it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
- should also include the value of getRatings() in the string
- Get and Set methods
- public int getYards()
- public void getYards(int yards)
- public int getMinutesPlayed()
- public void setMinutesPlayed(int minutesPlayed)
- public double getRatings()
- calculate and return the rates using this formula:
- (double) ( (yards - minutesPlayed/10.0) ) /gamesPlayed
- be careful with the parenthesis to avoid getting 0 as a result
- the (double) is called casting, forcing the expression that comes afterwards to become a double.
- it is necessary to avoid getting 0 as a result because of the precision loss in the division by integers
- use 10.0 instead of 10 to force Java to use more precision in the calculation
- if yards or gamesPlayed is 0, return 0 (you need to do this test to avoid the application crashing in case one of them is 0)
- (double) ( (yards - minutesPlayed/10.0) ) /gamesPlayed
- calculate and return the rates using this formula:
- public String toString()
Output
Important
- you need to display each class toString( ) in a separate line.
- You can do this by adding a " " at the end of the string.
- In the last toString you will also add a "=========..." string to close the line.
The output should be similar to
Person{name=John Doe, address=Address{number=0, name=N/A, type=Unknown, zip=00000, state= }} Player{number=0, sports=none, gamesPlayed=0} SoccerPlayer{goals=0, yellowCards=0, ratings= 0.0} ============================================================== Person{name=Julia Dohle, address=Address{number=210, name=Old Main, type=St., zip=16802-0001, state=PA}} Player{number=7, sports=Soccer, gamesPlayed=10} SoccerPlayer{goals=5, yellowCards=1, ratings= 0.4} ============================================================== Person{name=John Doe, address=Address{number=0, name=N/A, type=Unknown, zip=00000, state= }} Player{number=0, sports=none, gamesPlayed=0} FootballPlayer{yards=0, minutesPlayed=0, ratings=0.0} ============================================================== Person{name=Saquon Barkley, address=Address{number=210, name=Old Main, type=St., zip=16802-0001, state=PA}} Player{number=26, sports=Football, gamesPlayed=10} FootballPlayer{yards=80, minutesPlayed=220, ratings=5.8} ==============================================================App Person Creates a Soccer Player object spo using the no-parameter constructor. - Creates a SoccerPlayer object sp1 using the all-parameter constructor. Attributes private String name; private Address address; - Creates a FootballPlayer object fpo using the no-parameter constructor, - Creates a Footballplayer object fp1 using the all-parameter constructor. Constructors No-parameter All-parameter - Using the method toString(), display all the data from each of the 4 objects. Methods String toString() Get/Set methods Zip Code Address Textends Attributes private String five Digit; private String plus4; Attributes private int number; private String name; private String type; private Zip Code zip; private String state; Constructors No-parameter One-parameter Two-parameter abstract Player Attributes private int number; private String sports; Private int gamesPlayed; Constructors No-parameter All-parameter Constructors No-parameter All-parameter Methods String toString() Get/Set methods void display() void displayPrefix(int p) Methods String toString() Get/Set methods Methods String toString() Get/Set methods abstract double getRatings(); extends Soccer Player Attributes private int goals; private int yellow Cards; Football Player Attributes private int yards; private minutes Played; Constructors No-parameter . All-parameter Constructors No-parameter -parameter Methods String toString() Get/Set methods double getRatings Methods String toString() Get/Set methods double getRatings()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started