一个简易的customeruml
实现如下功能:
Customer类:客户类,name姓名 vip是否贵宾
Ticket类:票类,name票种类 price票单价
Order类:customer客户 ticket购买的票 qty数量 getPrice()返回实际单价,vip8折 getTotalPrice()返回订单金额
Customer类:
`public class Customer {
private String name ;
boolean vip;
public Customer(String name,Boolean vip){
this.name = name ;
this.vip = vip;
}
public String getName() {
return name;
}
public boolean isVip() {
return vip;
}
}`
Ticket类:
public class Ticket {
private String name ;
private double price;
public Ticket(String name ,double price){
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}
Order类:
public class Order {
private Customer customer;
private Ticket ticket;
private int qty;
public Order( Customer customer,Ticket ticket,int qty){
this.customer = customer;
this.ticket = ticket;
this.qty = qty;
}
public double getPrice(){
double price;
if(customer.vip)
price = 0.8 * ticket.getPrice();
else
price = ticket.getPrice();
return price;
}
public double getTotalPrice(){
double total;
total = getPrice() * qty;
return total;
}
public int getqty() {
return qty;
}
}
测试类TestCustomer:
public class TestCustomer {
public static void main(String[] args) {
Customer customer = new Customer("tom", true);
Ticket ticket = new Ticket("泰坦尼克号", 100.0);
Order order = new Order(customer, ticket, 12);
System.out.println("电影名称:"+'\t' + ticket.getName() + '\n' + "购票人:" +'\t'+ customer.getName() + '\n' +"单价:"+'\t' + order.getPrice() + "元"+ '\n' + "票数" +'\t'+ order.getqty()+ "张" + '\n'+ "总价:"+ '\t' + order.getTotalPrice() + "元") ;
}
}