Java exercises (06) various relationships

1. Title

1.   (0分)

java习题六--1题目描述
书上第六章课后习题7(P169页),具体内容见学习通通知“第六章习题7”
要求实现根据UML图实现各个类及类间关系。
在各个方法中添加适当的输出函数显示调用了该方法。
在主测试类中新建实例并调用各方法以显示相关内容。 
输入描述
无 
输出描述
无
package Ex01UML;

import java.sql.Date;



public class Main {
    
    
    public static void main(String[] args) {
    
    
//    	Customer customer = new Customer();
    	Customer customer = new Customer("郭德纲", "荷兰");
    	customer.getOrder().dispatch();
    	customer.getOrder().getOrderItem().calPrice();
    	customer.getOrder().close();
    	customer.getOrder().calTotalPrice();
    	CorporateCustomer corporateCustomer = new CorporateCustomer("星星", "荷兰", 
    			"ga", "100", "500");
    	corporateCustomer.billForMonth();
    	corporateCustomer.remind();
    	PersonalCustomer personalCustomer = new 
    			PersonalCustomer("郭德", "赫拉", 123);
    }
}

class Order {
    
    
	private Date dataReceived;
	private Boolean isPrepaid;
	private double price;
	private OrderItem orderItem = new OrderItem();
	Order(){
    
    }
	Order(Date dataReceived,Boolean isPrepaid,
			double price){
    
    
		this.dataReceived = dataReceived;
		this.isPrepaid = isPrepaid;
		this.price = price;
	}
	public OrderItem getOrderItem() {
    
    
		return this.orderItem;
	}
	public void dispatch() {
    
    
		System.out.println("dispatch");
	}
	public void close() {
    
    
		System.out.println("close");
	}
	public void calTotalPrice() {
    
    
		System.out.println("calTotalPrice");
	}
}

class OrderItem{
    
    
	private int quantity;
	private double price;
	private Product product = new Product();
	public Product getProduct() {
    
    
		return this.product;
	}
	public void calPrice() {
    
    
		System.out.println("calPrice");
	}
}


class Product{
    
    
	private String description;
	private double unitPrice;
	public String getDescription() {
    
    
		return this.description;
	}
	public double getUnitPrice() {
    
    
		return this.unitPrice;
	}
}


class Customer{
    
    
	private String name;
	private String address;
	private Order order = new Order();
	public String getCreditRatting() {
    
    
		return this.name +":"+this.address;
	}
	Customer(String name,String address){
    
    
		this.name = name;
		this.address = address;
	}
	public Order getOrder() {
    
    
		return this.order;
	}
}

class CorporateCustomer extends Customer{
    
    
	private String contactName;
	private String creditRatting;
	private String creditLimit;
	CorporateCustomer(String name,String address,
			String contactName,String creditRatting,
			String creditLimit){
    
    
		super(name, address);
		this.contactName = contactName;
		this.creditRatting = creditRatting;
		this.creditLimit = creditLimit;
	}
	public void billForMonth() {
    
    
		System.out.println("billForMonth");
	}
	public void remind() {
    
    
		System.out.println("remind");
	}
}

class PersonalCustomer extends Customer{
    
    
	private int creditCardNumber;
	PersonalCustomer(String name,String address,
			int creditCardNumber){
    
    
		super(name, address);
		this.creditCardNumber = creditCardNumber;
	}
}

Guess you like

Origin blog.csdn.net/weixin_44179485/article/details/108401009
Recommended