Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Ok so im getting ready to take my final for my java course this Friday and I'm studying my review. Here what the assignment

Hello,

Ok so im getting ready to take my final for my java course this Friday and I'm studying my review.

Here what the assignment says:

  • You are to highlight inYELLOWall polymorphic variable.
  • You are to highlight inGREENall polymorphic methods.
  • You are to highlight inBLUEall polymorphic method calls.

In the fellowing code, I did place the letter aside on right the mean the color I would highlight my answer.

I will use Y for Yellow, B for Blue , and G green.

I just someone took look over this code with letter aside and see if I got it write or wrong.

Please correct me if i get it wrong or if I'm missing something.

Thank you so much.

TestClass>

public class TestClass {

public static void main(String[] args) {

Person personArrayObject[] = new Person[100]; --> B

BaseballPlayer Hank = new BaseballPlayer("Hank", "H", "Aaron", 25, "Yankees", 10, "Runner"); B

String specaility[] = { "Attacker" };

FootballPlayer Terry = new FootballPlayer("Terry", "F.", "Bradshaw", 21, "Cowboy", 12, specaility); B

HockeyPlayer Mario = new HockeyPlayer("Mario", "", "Lemieux", 24, "Mighty Ducks", 9, "Bauer Supreme 2S."); B

Golfer Paula = new Golfer("Paula", "X.", "Creamer", 22, "Putter Face", 22, "PlayerOne"); B

SoccerPlayer Brain = new SoccerPlayer("Brian", "T.", "Rowe", 22, "Real Salt Lake", 4, "Defender"); B

BaseballPlayer Barry = new BaseballPlayer("Barry", "B.", "Bonds", 22, "Dodgers", 4, "Righthanded"); B

String specaility1[] = { "Attacker", "Defense" };

FootballPlayer Payton = new FootballPlayer("Payton", "A.", "Manning", 26, "New England Patriots", 9,

specaility1); B

HockeyPlayer Wayne = new HockeyPlayer("Wayne", "", "Gretzky", 33, "Boston Bruins", 9, "Bauer Vapor 1X."); B

Golfer Phil = new Golfer("Phil", "A.", "Mickleson", 26, "Par-tee On", 17, "UnderArmor");

SoccerPlayer Dom = new SoccerPlayer("Dom", "A.", "Dwyer", 21, "D.C United", 17, "Center midfielder"); B

BaseballPlayer Luis = new BaseballPlayer("Luis", "J.", "Sevillano", 33, "Miami Marlins", 10, "Runner"); B

String specaility2[] = { "Attacker" };

FootballPlayer Michael = new FootballPlayer("Michael", "", "Foscolos", 40, "Cleveland Browns", 11, specaility2); B

HockeyPlayer Nathalie = new HockeyPlayer("Nathalie", "A.", "Credido", 25, "Montreal Canadiens", 8,

"Dragon Nemesis"); B

Golfer Jasmyn = new Golfer("Jasmyn", "C.", "Taylor", 19, "21 Graemes", 21, "Nike"); B

SoccerPlayer Heather = new SoccerPlayer("Heather", "H.", "Turner", 20, "FC Dallas", 2, "Center Forward"); B

BaseballPlayer Zah = new BaseballPlayer("Zah", "Q.", "Raquel", 21, "Chicago Cubs", 6, "LeftHanded"); B

all Y's?

personArrayObject[0] = Hank;

personArrayObject[1] = Terry;

personArrayObject[2] = Mario;

personArrayObject[3] = Paula;

personArrayObject[4] = Brain;

personArrayObject[5] = Barry;

personArrayObject[6] = Payton;

personArrayObject[7] = Wayne;

personArrayObject[8] = Phil;

personArrayObject[9] = Dom;

personArrayObject[10] = Luis;

personArrayObject[11] = Michael;

personArrayObject[12] = Nathalie;

personArrayObject[13] = Jasmyn;

personArrayObject[14] = Heather;

personArrayObject[15] = Zah;

int R = 0;

while (R < 19) {

personArrayObject[R].displayPlayerDetails(); Y

personArrayObject[R].doThis(); Y

System.out.println();

R++;

}

}

} // End of TestClass.

Person Class>

public abstract class Person implements Display { // Parent class

protected String firstName; // Attributes.

protected String middleInitail;

protected String lastName;

protected int age;

public Person(String firstName, String middleInitail, String lastName, int age) {

super();

this.firstName = firstName;

this.middleInitail = middleInitail;

this.lastName = lastName;

this.age = age;

}

public String getFirstName() { // Getter firstName. G

return firstName;

}

public void setFirstName(String firstName) { // Setter for firstName. G

this.firstName = firstName;

}

public String getMiddleInitail() { // Getter middleName. G

return middleInitail;

}

public void setMiddleInitail(String middleInitail) { // Setter middleName.

this.middleInitail = middleInitail;

}

public String getLastName() { // Getter lastName. G

return lastName;

}

public void setLastName(String lastName) { // Setter lastName.

this.lastName = lastName;

}

public int getAge() { // Getter Age.

return age;

}

public void setAge(int age) { // Setter Age.

this.age = age;

}

public abstract void doThis();

public boolean equals(Object boo) { G Y

if (this == boo) B

return true;

if (boo == null) B

return false;

if (getClass() != boo.getClass())

return false;

Person otherThing = (Person) boo; Y

if (age != otherThing.age) {

return false;

}

if (firstName == null) {

if (otherThing.firstName != null) Y

return false;

} else if (!firstName.equals(otherThing.firstName)) Y

return false;

if (lastName == null) {

if (otherThing.lastName != null) {

return false;

} else if (!lastName.equals(otherThing.lastName)) { Y

return false;

}

B

if (middleInitail == null) {

if (otherThing.middleInitail != null) {

return false;

}

}

} else if (!middleInitail.equals(otherThing.middleInitail)) { B

return false;

}

return true;

}

public String toString() {

return " Person first name: " + getFirstName() + " Middle initail: " + getMiddleInitail() + " Last name: "

+ getLastName() + " Age: " + getAge();

}

}// End of Person.

Athletes Class>

public class Athletes extends Person { //Subclass.

protected String team; // Attributes.

protected int position;

// Constructor.

public Athletes(String firstName, String middleInitail, String lastName, int age, String team, int position) {

super(firstName, middleInitail, lastName, age);

this.team = team;

this.position = position;

}

public String getTeam() { // Getter for Team G

return team;

}

public void setTeam(String team) { // Setter for Team G

this.team = team;

}

public int getPosition() { // Getter Position. G

return position;

}

public void setPosition(int position) { // Setter for Postion. G

this.position = position;

}

public void doThis() {G

System.out.println("I love to play"); G

}

public void displayPlayerDetails() { B

String playerDetails = " Althlete: " + super.toString() + " Team: " + getTeam() + " Position: "

+ getPosition();

]

System.out.println(playerDetails);

}

public boolean equals(Object boo) { Y

if (this == boo)

return true;

if (!super.equals(boo)) { Y

return false;

}

if (getClass() != boo.getClass())

return false;

Athletes otherThings = (Athletes) boo; G

if (position != otherThings.position)

return false;

if (team == null) {

if (otherThings.team != null) Y

return false;

} else if (!team.equals(otherThings.team)) B

return false;

return true;

}

} // End of Athletes.

Baseball Class>

public class BaseballPlayer extends Athletes {

private String battingPosition;

public BaseballPlayer(String firstName, String middleInitails, String lastName, int age, String team, int position,

String battingPosition) {

super(firstName, middleInitails, lastName, age, team, position);

this.battingPosition = battingPosition;

}

public String getBattingPosition() { // Getter for Battle Position.

return battingPosition; G

}

public void setBattingPosition(String battingPosition) { // Setter for Battle Position.

this.battingPosition = battingPosition; G

}

public void doThis() { // doThis display message.

System.out.println(" I hit something."); G

}

public void displayPlayerDetails() { B

String baseDetails = " Baseball: " + super.toString() + " Team: " + getTeam() + " Batting Position: "

+ getBattingPosition();

System.out.println(baseDetails);

}

public boolean equals(Object base) { Y

if (this == base) {

return true;

}

if (!super.equals(base))

return false;

if (getClass() != base.getClass()) {

return false;

}

BaseballPlayer otherThings = (BaseballPlayer) base; G

if (battingPosition == null) {

if (otherThings.battingPosition != null) { Y

return false;

}

} else if (!battingPosition.equals(otherThings.battingPosition)) { B

return false;

}

return true;

}

}// End of BaseballPlayer

Soccer Class>

public class SoccerPlayer extends Athletes {

private String Posit;

public SoccerPlayer(String firstName, String middleInitail, String lastName, int age, String team, int position,

String Posit) {

super(firstName, middleInitail, lastName, age, team, position);

this.Posit = Posit;

}

public String getPosit() { G

return Posit;

}

public void setPosition(String posit) { G

Posit = posit;

}

public void doThis() {// toThis display message.

System.out.println(" I kick the ball.");

}

.

public void displayPlayerDetails() { G

String soccerDetails = " Soccer: " + super.toString() + " Team: " + getTeam() + " Position: " + getPosit();

System.out.println(soccerDetails); B

}

public boolean equals(Object soc) { /G

if (this == soc) {

return true;

}

if (!super.equals(soc)) G

return false;

if (getClass() != soc.getClass()) G

return false;

SoccerPlayer otherThings = (SoccerPlayer) soc; /G

if (Posit == null) {

if (otherThings.Posit != null) Y

return false;

} else if (!Posit.equals(otherThings.Posit)) {

return false;

}

return true;

}

}// End of SoccerPlayer.

Hockey class>

public class HockeyPlayer extends Athletes {

private String stickBrand;

public HockeyPlayer(String firstName, String middleInitail, String lastName, int age, String team, int position,

String stickBrand) {

super(firstName, middleInitail, lastName, age, team, position);

this.stickBrand = stickBrand;

}

public String getStickBrand() { // Getter for stick brand.

return stickBrand;

}

public void setStickBrand(String stickBrand) { // Setter for stick brand. G

this.stickBrand = stickBrand;

}

public void doThis() { // doThis display message.

System.out.println(" I sit in a penalty box"); G

}

public void displayPlayerDetails() {

String hockeyDetails = " Hockey: " + super.toString() + " Team: " + getTeam() + " Stick Brand: "

+ getStickBrand();

System.out.println(hockeyDetails);

}

public boolean equals(Object hock) { /Y

if (this == hock) {

return true;

}

if (!super.equals(hock))

return false;

if (getClass() != hock.getClass())

return false;

HockeyPlayer otherThings = (HockeyPlayer) hock; /G

if (stickBrand == null) {

if (otherThings.stickBrand != null) Y

return false;

} else if (!stickBrand.equals(otherThings.stickBrand)) Y

return false;

return true;

}

}// End of HockeyPlayer.

Football class>

import java.util.Arrays; //Array needed for option.

public class FootballPlayer extends Athletes {

private String specaility[];

public FootballPlayer(String firstName, String middleInitail, String lastName, int age, String team, int position,

String specaility[]) {

super(firstName, middleInitail, lastName, age, team, position);

this.specaility = specaility;

}

public String[] getSpecaility() { // Getter for specaility. ?B

return specaility;

}

public void setSpecaility(String[] specaility) { // setter for specaility. /B

this.specaility = specaility;

}

public void doThis() { Y

// Display Message. Y

System.out.println(" I tackle something.");

}

public void displayPlayerDetails() { B

String footDetails = " FootBall: " + super.toString() + " Team: " + getTeam() + " Speciality: "

+ Arrays.toString(specaility);

System.out.println(footDetails);

}

public boolean equals(Object foot) { /Y

if (this == foot) {

return true; Y

}

if (!super.equals(foot)) { G

return false;

}

if (getClass() != foot.getClass()) { G

return false;

}

FootballPlayer otherThings = (FootballPlayer) foot; G

if (!Arrays.equals(specaility, otherThings.specaility)) { B

return false;

}

return true;

}

} // End of FootballPlayer.

Golfer class>

public class Golfer extends Athletes { // SuperClass.

private String mainSponsor; // Attributes

public Golfer(String firstName, String middleInitail, String lastName, int age, String team, int position,

String mainSponsor) { // Constructor. Y

super(firstName, middleInitail, lastName, age, team, position);

this.mainSponsor = mainSponsor; Y

}

public String getMainSponser() { // Getter for Sponsor. G

return mainSponsor;

}

public void setMainSponser(String mainSponser) { // Setter for Sponsor. G

this.mainSponsor = mainSponser;

}

public void doThis() { // doThis display message.

System.out.println(" I putt it in the hole."); G

}

public void displayPlayerDetails() { G

String golferDetails = " Golfer: " + super.toString() + " Team: " + getTeam() + " Main Sponsor: "

+ getMainSponser();

System.out.println(golferDetails); B

}

.

public boolean equals(Object golf) { G

if (this == golf)

return true;

if (!super.equals(golf)) {

return false;

}

if (getClass() != golf.getClass()) { G

return false;

}

Golfer otherThings = (Golfer) golf; G

if (mainSponsor == null) {

if (otherThings.mainSponsor != null)

return false;

} else if (!mainSponsor.equals(otherThings.mainSponsor)) { /B

return false;

}

return true;

}

}// End of Golfer.

Display interface class>

public interface Display {

public abstract void displayPlayerDetails(); Y

}

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

Students also viewed these Programming questions