11A
Write an interface Qualifiable
. It has one method qualify()
which determines if the object qualifies according to some set of criteria. It returns true if the object qualifies and returns false otherwise.
Now modify the Person
class included in Codecheck so that it implements Qualifiable
. A person qualifies if his or her annual income is less that 20,000. Something like this could be used to determine if a person qualified for free health insurance under the Affordable Care Act.
For the draft, just write the Qualifiable
interface. There a 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. The draft is one problem you will have to test in Codecheck. You will not write a Fake
class
To add an interface to a Bluej project, click New Class... and select interface. Interface names should start with uppercase just like class names.
In the final, you will need to upload the interface as well as the Person
class in Codecheck
11B
Write a class to model a Computer
. A Computer
has a constructor that takes the brand as a String. It also takes a double gigahertz. Call the instance variables brand
and ghz
. Gigahertz is a measure of the clock speed of a computer. Computer
has methods getGhz()
and getBrand
. Computer
implements the the Comparable
interface. Computers
are ordered by gigahertz. If two Computers
have the same speed (gigahertz), then the Computer
with the brand that comes first in the lexicographical (alphabetical) order is the smaller. For Example, "Apple" comes before "Surface" and so is the smaller.
Provide Javadoc
Remember that the compareTo
method take a Object
as parameter not a Computer
(That means you will have to cast)
The starter class has a toString
method for testing.
For the draft, supply the instance variables and the constructor.
11C
Make a subclass Candy
of the Product
class we created in class. Besides the price
and description
inherited from Product
, Candy
also has an instance variable gramsOfFat
. Do not redefine price and description.
Candy
has a methods:
public void setGramsOfFat(int fat)
public int getGramsOfFat()
public boolean healthier(Candy other)
which tells if this Candy
is healthier than the other based on gramsOfFat
. If this Candy
has fewer grams of fat than the other Candy
, return true. Otherwise, return false.Provide Javadoc.
For the draft, provide the new instance variable,gramsOfFat
. Write the constructor that takes price
, description
, and gramsOfFat
, in that order. Be sure to initialize all the instance variables. Implement healthier
as a stub. Remember that if a stub's return type is boolean, return false.