一个简易的customeruml

一个简易的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() + "元") ;
	
	
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值