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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT