the following Monster class: package comparators; public class Monster { private String name; private int hitPoints; private int id; public Monster(String name, int hitPoints, int id) { this.name = name; this.id = id; this.hitPoints = hitPoints; } public String getName() {return this.name;} public int getHitPoints() {return this.hitPoints; } public int getId() {return this.id;} @Override public boolean equals(Object other) { if (other == this) return true; if (other.getClass() != this.getClass()) return false; if (this.name.equalsIgnoreCase(((Monster)other).name) && (this.id == ((Monster)other).id)){ return true; } return false; } } (a) Create a Comparator called MonsterComparator that will allow us to sort a list of monsters in ascending order, by their names (b) Create a second comparator, called MonsterHPComparator that will allow us to sort a list of monsters from least to greatest with respect to their hitPoints power
Given the following Monster class:
package comparators;
public class Monster {
private String name;
private int hitPoints;
private int id;
public Monster(String name, int hitPoints, int id) {
this.name = name;
this.id = id;
this.hitPoints = hitPoints;
}
public String getName() {return this.name;}
public int getHitPoints() {return this.hitPoints; }
public int getId() {return this.id;}
@Override
public boolean equals(Object other) {
if (other == this) return true;
if (other.getClass() != this.getClass()) return false;
if (this.name.equalsIgnoreCase(((Monster)other).name)
&& (this.id == ((Monster)other).id)){
return true;
}
return false;
}
}
(a) Create a Comparator called MonsterComparator that will allow us to sort a list of monsters in ascending order, by their names
(b) Create a second comparator, called MonsterHPComparator that will allow us to sort a list of monsters from least to greatest with respect to their hitPoints power.
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)