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

                362 Chapter 9 Classes with Class Members
 /**************************************************************
*
Agent.java
Dean & Dean
Class that describes agents that collect quantitative values.
**************************************************************/
*
*
*
import java.util.Scanner;
public class Agent
{
private static Agent listOfAgents = null;
private final String NAME;
private double value = 0.0;
private Agent nextAgent;
// head of list
// next in list
//***********************************************************
public Agent(String name)
{
   }
this.NAME = name;
this.nextAgent = listOfAgents;⎫⎬ listOfAgents = tAhips;ago PD⎭F // end constructor
//***********************************************************
private double getValue()
{
}
return this.value;
//***********************************************************
private void addValue()
{
}
Scanner stdIn = new Scanner(System.in);
System.out.printf("Enter %s's contribution: ", this.NAME );
this.value += stdIn.nextDouble();
// end addValue
This inserts each new object at the
Enhancer
head of the linked list.
Figure 9.9a First part of Agent class of FundRaiser program
This code and the code in 9.9b are driven by the FundRaiser class in Figure 9.8.
























































   394   395   396   397   398