简单模拟一个商店客户折扣卡的功能,自定义Customer类用来保存了在某个商店中的客户的折扣卡信息。在主类CustomerDemo中,创建Customer类的一个数组对象,该数组中包含了三个Customer的对象,用来保存不同的三个消费者各自持有的折扣卡信息。通过这三个对象,可以根据用户消费的金额来改变用户在本店中所能享受到的折扣价格。
代码如下:
public class CustomerDemo {
class Customer
{
private String cardID;
private String name;
private double cost = 0;
private String address;
private String email;
private double discount = 1;
public Customer(String id,String name,String add,String email)
{
cardID = id;
this.name = name;
address = add;
this.email=email;
}
public void buy(double cost)
{
this.cost +=cost;
}
public void setDiscount()
{
if (cost>2000.00)
discount -= 0.1;
else if (cost>1000.00)
discount -=0.05;
}
public void setAddress(String address)
{
this.address=address;
}
public String getAddress()
{
return add