打印购买货物清单2

Customer.java

public class Customer {
	
	String name;
	String type;
	
	Customer(String name, String type) {
		this.name = name;
		this.type = type;
	}
	
	String getInfo(){
		return "客户姓名:"+this.name+"\n"+
				"客户类型:"+this.type;
	}

}

Product.java

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class Product {


	String name;
	int date;
	int bxy;
	double price;
	
	
	Product(String name,int date,int bxy,double price){
		this.name = name;
		this.date = date;
		this.bxy = bxy;
		this.price = price;
	}
	String getInfo(){
	 return "品               牌:"+this.name+"\n"+
			"购  买  日 期:"+this.date+"\n"+
			"规定保修月:"+this.bxy+"\n"+
			"单               价:"+this.price+"\n"+
			"------------保          修到期时间:"+this.getEndTime();
	}
	int getEndTime(){
		return this.date+this.bxy;
	}
}

Order.java

import java.text.DecimalFormat;

public class Order {
	
	Product pro[];
	Customer cus;
	int CEndTime;
	
	
	Order(Product[] pro, Customer cus) {
		this.pro = pro;
		this.cus = cus;
	}
	
	String printOrder(){
		return "********客户信息*********\n"+
			cus.getInfo()+"\n"+
			"********商品信息**********\n"+
			getAllProInfo();
	}
	
	/*
	 * 获取商品信息
	 */
	String getAllProInfo(){
		String info="";
		
		for (int i = 0; i < pro.length; i++) {
			if(cus.type.equals("非会员")){
				CEndTime+=pro[i].getEndTime();
			}
			if(cus.type.equals("普通会员")){
				CEndTime+=pro[i].getEndTime()+5;
			}
			if(cus.type.equals("黄金会员")){
				CEndTime+=pro[i].getEndTime()+10;
			}
			info+=pro[i].getInfo()+"\n"+
			      "------------会员保修到期时间:"+CEndTime+"\n";
			CEndTime=0;
		}
		
		return info;
	}
	
	
	


}

Test.java

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class Test {
	
	public static void main(String[] args) {
		Product pro1=new Product("IBM x200",201212,24,5400);
		Product pro2=new Product("HP 520",2,201109,5400);
		Product pro3=new Product("DELL 1000",201109,18,5400);
		Product pro4=new Product("神州 100",201109,16,5400);
		
		Customer cus1=new Customer("小明","非会员");
		Customer cus2=new Customer("小丽","普通会员");
		Customer cus4=new Customer("小孙","黄金会员");
		
		Order ord[]={
			new Order(new Product[]{pro1,pro2},cus1),
			new Order(new Product[]{pro2,pro3,pro4},cus2)
		};
		
		for (int i = 0; i < ord.length; i++) {
			System.out.println(ord[i].printOrder());
		}
	}

}
打印购买货物清单2

 

你可能感兴趣的:(等闲识却,打印货物清单)