文章目錄
一.UML基礎
- (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;
}
}