Page 392 - Introduction to Programming with Java: A Problem Solving Approach
P. 392

                358 Chapter 9 Classes with Class Members
 /**************************************************************
*
PennyJarDriver.java
Dean & Dean
This class drives the PennyJar class.
**************************************************************/
*
*
*
public class PennyJarDriver
{
}
// end class PennyJarDriver
public static void main(String[] args)
{
}
PennyJar pennyJar1 = new PennyJar();
PennyJar pennyJar2 = new PennyJar();
pennyJar1.addPenny();
pennyJar1.addPenny();
pennyJar2.addPenny();
System.out.println(pennyJar1.getPennies());
System.out.println(PennyJar.getAllPennies());
// end main
Output:
 Clink! Apago PDF Enhancer Clink!
Clink!
2
3
Figure 9.6 Driver for the PennyJar class in Figure 9.5
9.7 Problem Solving with Class Members and Instance Members
in a Linked List Class (Optional)
The previous PennyJar program is admittedly just a “toy” program, but sometimes toy programs can help you learn new techniques. In this section, you’ll use the case-based design approach described in Chapter 8 and turn the PennyJar program into something more practical.
FundRaiser Program
Adapt a previous Each penny jar is an agent in the process of collecting money. Think of the agent as a
         program to a new purpose.
The Agent class should have methods that are similar to the methods in the PennyJar class. You can replace the getPennies instance method with a getValue instance method, the addPenny instance
human solicitor. Then the collection of all penny jars becomes a body of people working
  in an organized fund-raising activity. The penny jar pennies become donation pledges, and the GOAL of 10,000 pennies becomes a GOAL of 10,000 dollars in donations. Now for the big picture: Replace the PennyJar class with a more general Agent class. And replace the PennyJarDriver class with a FundRaiser class.
   


























































   390   391   392   393   394