Question: This assignment is from a chapter called abstract classes and interfaces Create class called Player that has the following attributes: (See below) Notes: All attributes

This assignment is from a chapter called abstract classes and interfaces

Create class called Player that has the following attributes: (See below)

Notes:

All attributes should not be allowed to be set below 0.

Player
Health - Integer
Intelligence - Integer
Dexterity - Integer
Strength - Integer
Stamina - Integer
Player()
Player(Health, Intelligence, Dexterity, Strength, Stamina)
getHealth() - Integer
setHealth(Integer) - Void
getIntelligence() - Integer
setIntelligence(Integer) - Void
getDexterity() - Integer
setDexterity(Integer) - Void
getStrength() - Integer
setStrength(Integer) - Void
getStamina() - Integer
setStamina(Integer) - Void
toString() - String
compareTo(Player) - Integer
equals(Player) - Boolean

I mainly need help with the compareTo() method because I am uncertain of which Integer to use..if that makes sense? This is what is confusing for me. Please explain.

What I have so far:

public class Player {

private int Health; private int Intelligence; private int Dexterity; private int Strength; private int Stamina; public Player() { } public Player (int Health, int Intelligence, int Dexterity, int Strength, int Stamina) { this.Health = Health; this.Intelligence = Intelligence; this.Dexterity = Dexterity; this.Strength = Strength; this.Stamina = Stamina; if (Health < 0) { System.out.println("Health can not be less than 0"); } if (Intelligence < 0) { System.out.println("Intelligence picking ability can not be less than 0"); } if (Dexterity < 0) { System.out.println("Dexterity can not be less than 0"); } if (Strength < 0) { System.out.println("Strength picking ability can not be less than 0"); } if (Stamina < 0) { System.out.println("Stamina picking ability can not be less than 0"); }

}

public int getHealth() { return Health; }

public void setHealth(int health) { Health = health; if (health < 0) { System.out.println("Health can not be set below 0"); } }

public int getIntelligence() { return Intelligence; }

public void setIntelligence(int intelligence) { Intelligence = intelligence; if (intelligence < 0) { System.out.println("Intelligence can not be set below 0"); } }

public int getDexterity() { return Dexterity; }

public void setDexterity(int dexterity) { Dexterity = dexterity; if (dexterity < 0) { System.out.println("Dexterity can not be set below 0"); } }

public int getStrength() { return Strength; }

public void setStrength(int strength) { Strength = strength; if (strength < 0); System.out.println("Strength can not be set below 0"); }

public int getStamina() { return Stamina; }

public void setStamina(int stamina) { Stamina = stamina; if (stamina < 0) { System.out.println("Stamina can not be set below 0"); } }

@Override public String toString() { return "Player [Health=" + Health + ", Intelligence=" + Intelligence + ", Dexterity=" + Dexterity + ", Strength=" + Strength + ", Stamina=" + Stamina + "]"; }

@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Player other = (Player) obj; return Dexterity == other.Dexterity && Health == other.Health && Intelligence == other.Intelligence && Stamina == other.Stamina && Strength == other.Strength; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!