The Customer Class
Listing 9.1 (Customer.java)
import java.io.*;
public class Customer
implements Serializable{
//instance variables
private String name;
private int age;
private String item;
//constructor
public Customer(String name,int age, String item){
this.name = name;
this.age = age;
this.item = item;
}
//method used to set name
public void setName(String name){
this.name = name;
}
//method used to set age
public void setAge(int age){
this.age = age;
}
//method used to set Item
public void setItem(String item){
this.item = item;
}
//method used to get name
public String getName(){
return name;
}
//method used to get age
public int getAge(){
return age;
}
//method used to get Item
public String getItem(){
return item;
}
}
Explanation
Objects of Customer class will be passed
across a network. The class is not remote, so its methods can not be
invoked remotely. Note that the Customer
class implements the Serializable interface.
Therefore, objects of this class can be transported from one machine
to another but the receiving machine will get the copy of the actual
object.
The Constructor of the class takes three arguments:
Name
of the customer.
Age
of the customer.
Item
bought by the customer.
Further, the class provides some accessor and mutator methods.
|