12A
Write the interface Growable
. Growable
interface has one method, grow
. The grow
method takes a double parameter percentToGrow
as a parameter and does not return any value.
Now modify the class Circle
included in Codecheck to implement the Growable
interface. Circle's grow()
method will increase the radius by the given percent.
For the draft, just write the Growable
interface. There a hidden class Fake
in Codecheck. It let's me test your interface. Do not worry about it. You can not compile and execute the Runner
class in Bluej. This is another problem you will have to test in Codecheck. You will not write a Fake
class.
You will need to resubmit your interface along with the Circle to Codecheck or the final
12B
Modify the class Country
to implement the Comparable
interface from the Java library. (Do not write your own interface). Countries
are ordered by area. One Country
is smaller than another if its area is smaller. If two countries have the same area, the one with the name that comes first in alphabetical order is smaller.
For the draft, add the implements Comparable
clause to the Country
class and then implement compareTo
as a stub that always returns 0.
12C
Implement a subclass of Product
called Book
. Book
has a String instance variable, author, in addition to description and price.
Provide the instance variable and methods
public void setAuthor(String newAuthor)
public String getAuthor()
public boolean sameAuthor( Book other)
returns true if the books have the same author. Otherwise falseFor the draft, start the Book
class as a subclass of Product
. Provide the new instance variable, author. Write the constructor that takes price, description, and author, in that order. Be sure to initialize all the instance variables. Implement sameAuthor
as a stub. Remember that if a stub's return type is boolean, return false.