Remember not to create packages. Use the default package
A
Write a Snack
class as a subclass of Product
. In addition to description and price, Snack
has integer instance variable gramsOfFat.
Write a method getGramsOfFat
.
Write a method isHealther
which returns true if this Snack has fewer grams of fat than the parameter Snack.
Include toString and equals.
Snack should implement Comparable
interface. Snacks
are ordered first by gramsOfFat with the Snack
with the fewer grams of fat coming first. If the grams of fat are the same order by price with the lowest price coming first, If prices are also equal, order alphabetically by description
Implement the Clonable
interface
B
You are given a CollegeWrestler
class. A CollegeWrestler
has a String name and a weight as a double. We need to order wrestlers in two ways: alphabetically by name and by weight. We can not do this with the Comparable
interface.
Create two Comparator
objects, one to handle each type of ordering. You can do this several different ways. If you write separate classes, call then CollegeWrestlerComparatorByWeight and CollegeWrestlerComparatorByName. If you use inner classes or anonymous inner classes in ComparatorRunner
, just leave the text area for the Comparator files empty.
Then complete the ComparatorRunner
class. It defines an ArrayList of CollegeWrestlers
.
Sort by weight and then loop through the ArrayList printing the weight and then the name of each CollegeWrestlers
(use Collections.sort)
Sort by name and then loop through the ArrayList printing the name and then the weight of each CollegeWrestlers
.(use Collections.sort)