Question
Lab Description : Create a Monster class to store Monster information. The Monster class must implement the Comparable interface. Sample Output : zero Monster ::
Lab Description : Create a Monster class to store Monster information. The Monster class must implement the Comparable interface. Sample Output : zero Monster :: 0 0 0 one Monster :: 8 0 0 sue Monster :: 9 4 0 harry Monster :: 1 2 3 changing harry's properties harry Monster :: 7 6 5 cloning harry sue Monster :: 7 6 5 Monster 1 :: 33 33 11 Monster 2 :: 55 33 11 mOne.equals(mTwo) == false mOne.compareTo(mTwo) == -1 mTwo.compareTo(mOne) == 1 public int compareTo(Object obj) compareTo will compare this object with the parameter obj. compareTo will return a negative integer for less than, a positive integer for greater than, and a zero for equality. 0 for equality one.compareTo(two) >0 for greater than big.compareTo(little) <0 for less than whoot.compareTo(runner) How do you compare Monsters? 1 st criteria Height 2 nd criteria Weight 3 rd criteria Age Monster 1 - Ht 900 Wt 987 - Age 25 Monster 2 - Ht 900 Wt - 876 - Age 76 Monster 1 is larger than Monster 2. compareTo( ) returns a 1! Monster 1 - Ht 800 Wt 987 - Age 25 Monster 2 - Ht 810 Wt - 76 - Age 11 Monster 2 is larger than Monster 1. compareTo( ) returns a -1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started