12A
Modify the BankAccount
class from 11A to implement the Comparable
interface from the Java library. (Do not write your own interface). BankAccount
class will implement Comparable
in addition to Qualifiable
. There is a correct version of the BankAccount
solution for 11a in the modules in Canvas if you need it. One BankAccount
comes before another if its balance is smaller (compareTo
will return a negative number). One BankAccount
comes after another if its balance is larger (compareTo
will return a positive number). If the two BankAccount
have the same balance, then the BankAccount
with the String accountId that comes first in alphabetical order is smaller. Use String's compareTo number.
For the draft, add the implements Comparable
clause to the BankAccount
class and then implement compareTo
as a stub that always returns 0.
12B
You are given a class Critter
which represents an animal. Critter
class will be the superclass of a set of subclasses classes. A Critter
has a weight and a position on a number line. The constructor initializes the position to 0 and sets the weight from the parameter. It has an ArrayList of Strings to keep a log of its activities. It has other methods you can view by opening the class in Bluej and then selecting Documentation from the drop down menu on the right.
You are to implement the following subclasses of Critter
SpeedyCritter
: A SpeedyCritter
moves twice as fast as a Critter
so if the SpeedyCritter's
move method is called with a value of 5, it should actually move 10 steps. You will override the move method.
LazyCritter
only eats and sleeps : A LazyCritter
only has two activities: eat and sleep. When asked to move, it will either eat or sleep. A LazyCritter
is created hungry so the first time its move method is called, the LazyCritter
should eat. (and add the word "eat" to the history. The next time the move method is called, the LazyCritter
will sleep (and add the word "sleep" to the history). It will continue to alternate activities in this manner. You will need a boolean variable to keep track of which activity the LazyCritter
should do next. This variable should be set in such a manner in the constructor that in the first call to move method, it will eat.
StubbornCritter
: A StubbornCritter
only moves every third time you tell it it move. You will override the move method. If you call the StubbornCritter
's move method 4 times, it will move the requested amount, not move, not move, move the requested amount. (The % operator is handy here)
DescriptiveCritter
: DescriptiveCritter
has an additional instance variable - a String description. It has getDescription
and setDescription
methods
For the draft, implement SpeedyCritter
For the final, you will need to submit all 4 subclasses
12C
You will write a utility class called MyUtilities
. The class will have several static methods to process arrays and array lists. It will not have any instance methods or variables. It will not have a constructor.
sum
which takes an array of doubles as a parameter and gets the sum of the element in the array as a double. The array may be any length > 0sum
which takes an array of integers as a parameter and gets the sum of the elements in the array as an int. This is an example of overloading. The array may be any length > 0search
which takes two parameters, an int array and a target. The method returns the index of the first occurrence in the array of the target or -1 if the target is not in the array. The array may be any length > 0max
which takes a 2d array of ints as a parameter and returns the largest number in the array. The array may have 2 or more rows and 2 or more columnsmax
that takes an ArrayList of Rectangle objects and returns the the value of the largest perimeter in the ArrayList. The array list can be any size. If it is empty, return -1. This is another example of overloading. Supply Javadoc
For the draft, implement the first two methods along with their Javadoc.