Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise, you have to use java Interface. Imagine you are writing a comp

ID: 3732381 • Letter: I

Question

In this exercise, you have to use java Interface. Imagine you are writing a computer game that involves a hero who encounters various monsters. Monsters have several characteristics: hit points, strength, age, and name (the class Monster.jova is supplied). The number of hit points a monster has is how far it is from death. A monster with a large number of hit points is hard to kill. Similarly, the hero also has hit points. When the hit points of the hero reach zero, the game is over. The strength of a monster affects how many hit points the hero loses when the monster hits the hero. The age and name of the monster do not affect the outcome of battles between the monster and the hero. make the necessary changes to the Monster class (supplied with this lab) and write a tester (client) class with main method that will present the hero with monsters in increasing order of difficuity. Hints: Monster needs a compareTol) method.

Explanation / Answer

public class Monster implements Comparable{ private int hitPoints, strength, age; private String name; public Monster(int hitPoints, int strength, int age, String name) { this.hitPoints = hitPoints; this.strength = strength; this.age = age; this.name = name; } public int getHitPoints() { return hitPoints; } public int getStrength() { return strength; } public int getAge() { return age; } public String getName() { return name; } @Override public String toString() { return "HP: " + getHitPoints() + " Str: " + getStrength() + " " + getName(); } @Override public int compareTo(Monster other) { return Integer.compare(strength+hitPoints, other.strength+other.hitPoints); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote