Java Reference
In-Depth Information
Account objects interact with Transaction objects, which have many methods including
Returns the value of this transaction in pennies (could be negative,
positive or zero)
public int value()
Design a new class called FilteredAccount whose instances can be used in place of normal accounts but which
include the extra behavior of not processing transactions with a value of 0. More specifically, the new class should
indicate that a zero-valued transaction was approved but shouldn't call the process method for it. Your class should
have a single constructor that accepts a parameter of type Client , and it should include the following method:
Returns the percent of transactions filtered out (between 0.0
and 100.0); returns 0.0 if no transactions are submitted
public double percentFiltered()
11. Add an equals method to the TimeSpan class introduced in Chapter 8. Two time spans are considered equal if they
represent the same number of hours and minutes.
12. Add an equals method to the Cash class introduced in this chapter. Two stocks are considered equal if they repre-
sent the same amount of cash.
13. Add an equals method to each of the Rectangle , Circle , and Triangle classes introduced in this chapter. Two
shapes are considered equal if their fields have equivalent values.
14. Write a class named Octagon whose objects represent regular octagons (eight-sided polygons). Your class should
implement the Shape interface defined in this chapter, including methods for its area and perimeter. An Octagon
object is defined by its side length. (You may need to search online to find formulas for the area and perimeter of a
regular octagon.)
15. Write a class named Hexagon whose objects represent regular hexagons (6-sided polygons). Your class should
implement the Shape interface defined in this chapter.
16. Declare an interface called Incrementable which represents items that store an integer that can be incremented in
some way. The interface has a method called increment that increments the value and a method called getValue
that returns the value. Once you have written the interface, write two classes called SequentialIncrementer and
RandomIncrementer that implement the interface. The SequentialIncrementer begins its value at 0 and
increases it by 1 each time it is incremented. The RandomIncrementer begins its value at a random integer and
changes it to a new random integer each time it is incremented.
Programming Projects
1. Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for
getting information such as the volume and surface area of a three-dimensional shape. Then make classes and sub-
classes that implement various shapes such as cubes, rectangular prisms, spheres, triangular prisms, cones, and cylin-
ders. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add meth-
ods to the subclasses to represent the unique behavior of each three-dimensional shape, such as a method to get a
sphere's radius.
 
Search WWH ::




Custom Search