The GameItem class represents game items that provide modifiers to strength, speed, and intelligence. It contains private fields for each attribute, and public getters to access them. It includes methods to compare items, check for duplicates, make copies, and output attributes as a string.
Need uml diagram for this class please public class GameItem { pr.pdf
1. Need uml diagram for this class please
public class GameItem {
private String name;
private int id;
private int strengthModifier;
private int speedModifier;
private int intelligenceModifier;
public GameItem(String name, int id, int strengthModifier, int speedModifier, int
intelligenceModifier) {
this.name = name;
this.id = id;
this.strengthModifier = strengthModifier;
this.speedModifier = speedModifier;
this.intelligenceModifier = intelligenceModifier;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public int getStrengthModifier() {
return strengthModifier;
}
public int getSpeedModifier() {
return speedModifier;
}
public int getIntelligenceModifier() {
return intelligenceModifier;
}
public void Comparison(GameItem c){
System.out.println("Item 1:ttItem 2:");
System.out.println(this.strengthModifier + "t |t" + c.strengthModifier);
System.out.println(this.speedModifier+ "t |t" + c.speedModifier);
System.out.println(this.intelligenceModifier + "t |t" + c.intelligenceModifier);
}
2. public boolean equals(GameItem other) {
return strengthModifier == other.strengthModifier && speedModifier == other.speedModifier
&& intelligenceModifier == other.intelligenceModifier;
}
// Declare a method that checks if two GameItems are duplicates
public boolean isDuplicate(GameItem other) {
return name.equals(other.name) && id == other.id && equals(other);
}
// Declare a method that creates a copy of a GameItem
public GameItem copy() {
return new GameItem(this.name, this.id, this.strengthModifier, this.speedModifier,
this.intelligenceModifier);
}
@Override
public String toString() {
return "GameItem{" + "name=" + name + ", id=" + id + ", strengthModifier=" +
strengthModifier + ", speedModifier=" + speedModifier + ", intelligenceModifier=" +
intelligenceModifier + '}';
}
}