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

                contains two accessor methods, getName and getSales. It contains an adjustSales method that updates the sales clerk’s total sales value by adding the passed-in amount to the sales instance variable. See the SalesClerk class in Figure 10.23 and verify that it does what it’s supposed to do.
Now look at the main method in the Figure 10.24’s SalesClerksDriver class. In a declaration, it instantiates a SalesClerks object, passing an initial array-length value of 2 to the SalesClerks
10.10 Arrays of Objects 407
 /******************************************************************
*
SalesClerk.java
Dean & Dean
This class stores and retrieves a sales clerk's data.
*******************************************************************/
*
*
*
public class SalesClerk
{
}
// end class SalesClerk
private String name;
// sales clerk's name
private double sales = 0.0; // total sales for clerk
//***************************************************************
public SalesClerk(String name)
{
}
this.name = name;
Apago PDF Enhancer
//***************************************************************
public String getName()
{
}
}
return name;
public double getSales()
{
return sales;
//***************************************************************
// Adjust clerk's total sales by adding the passed-in sale.
public void adjustSales(double amount)
{
}
sales += amount;
Figure 10.23
SalesClerk class

























































   439   440   441   442   443