Day6 洗车系统

题目

顾客预约了明天下午三点到店里洗车,Java描述

示例代码
1.新建一个顾客类


public class Customer {
   private String name;
   private String mobile;
   public String getName() {
   	return name;
   }
   public void setName(String name) {
   	this.name = name;
   }
   public String getMobile() {
   	return mobile;
   }
   public void setMobile(String mobile) {
   	this.mobile = mobile;
   }

} 

2.新建一个车类


public class Car {
  private String name;
  private String color;
  private String no;
  private Customer customer;
  public String getName() {
  	return name;
  }
  public void setName(String name) {
  	this.name = name;
  }
  public String getColor() {
  	return color;
  }
  public void setColor(String color) {
  	this.color = color;
  }
  public String getNo() {
  	return no;
  }
  public void setNo(String no) {
  	this.no = no;
  }
  public Customer getCustomer() {
  	return customer;
  }
  public void setCustomer(Customer customer) {
  	this.customer = customer;
  }
  
}

3.新建一个订单类


import java.util.Date;
/**
* 订单类
* @author jiyu
*
*/
public class Order {
   //预约的车
   private Car car;
   //订单类型,比如洗车,或者修车,或者保养
   private String type;
   //创建订单的时间
   private Date createDate;
   //预约的时间
   private Date bookDate;
   //服务的门店
   private Shop shop;
   //必填字段,可以放在构造方法
   public Order(Car target,Shop shop, Date d, String type){
   	// 表示new订单对象的时候,就直接把当前的日期,赋值给了 创建订单时间变量
   	this.createDate=new Date();
   	this.car=target;
   	this.shop=shop;
   	this.type=type;
   	this.bookDate=d;
   }
   public Car getCar() {
   	return car;
   }
   public void setCar(Car car) {
   	this.car = car;
   }
   public String getType() {
   	return type;
   }
   public void setType(String type) {
   	this.type = type;
   }
   public Date getCreateDate() {
   	return createDate;
   }
   public void setCreateDate(Date createDate) {
   	this.createDate = createDate;
   }
   public Date getBookDate() {
   	return bookDate;
   }
   public void setBookDate(Date bookDate) {
   	this.bookDate = bookDate;
   }
   public Shop getShop() {
   	return shop;
   }
   public void setShop(Shop shop) {
   	this.shop = shop;
   }
   
   
   

}

4.新建一个商店类


public class Shop {
   private String address;
   private String name;
   private String mobile;
   public String getAddress() {
   	return address;
   }
   public void setAddress(String address) {
   	this.address = address;
   }
   public String getName() {
   	return name;
   }
   public void setName(String name) {
   	this.name = name;
   }
   public String getMobile() {
   	return mobile;
   }
   public void setMobile(String mobile) {
   	this.mobile = mobile;
   }
   

}

5,新建一个预约方法并打印


import java.util.ArrayList;
import java.util.Date;

public class OrderController {
   ArrayList orderlist=new ArrayList();
   //预约
   public boolean book(Car target, Date d, String type){
   	boolean rs=false;
   	Shop shop=new Shop();
   	shop.setAddress("上海市浦东新区临港大道101号");
   	shop.setMobile("155487533");
   	shop.setName("汽车之家");
   	if(orderlist.size()<10){
   		Order order=new Order( target, shop,  d,  type);
   		orderlist.add(order);
   		rs=true;
   	}else{
   		System.out.println("预约已满");
   	}
   	return rs;
   }
   
   //完成订单
   public boolean finishOder(Order order){
   	return orderlist.remove(order);
   }
   
   
   //查看门店所有订单
   public ArrayList showAll(){
   		return orderlist;
   	}
   
   //打印所有订单
   	public void print(){
   			for(int i=0;i<orderlist.size();i++){
   				Order o=(Order) orderlist.get(i);
   				System.out.println(o.getCar().getCustomer().getName());
   				System.out.println("下单时间:"+o.getCreateDate());
   				System.out.println("预约车辆:"+o.getCar().getColor()+o.getCar().getName()+o.getCar().getNo());
   				System.out.println("预约时间:"+o.getBookDate());
   				System.out.println("服务类型:"+o.getType());
   			}
   		}


}

6.测试


import java.util.Date;

public class Test {

   public static void main(String[] args) {
   	// TODO Auto-generated method stub
   	
   	Customer c=new Customer();
   	c.setMobile("177777");
   	c.setName("顾客 李先生");
   	Car car=new Car();
   	car.setColor("红色");
   	car.setCustomer(c);
   	car.setName("宝马");
   	car.setNo("沪A34343");
   	Date d=new Date(119,7,11,15,0,0);
   	OrderController ordercontroller=new OrderController();
   	ordercontroller.book(car, d, "洗车");
   	ordercontroller.print();
   	

   }

}

测试结果

顾客 李先生
下单时间:Sat Jul 13 09:48:45 CST 2019
预约车辆:红色宝马沪A34343
预约时间:Sun Aug 11 15:00:00 CST 2019
服务类型:洗车

上一篇:94Echarts - 地理坐标/地图(Use lines to draw 1 million ny streets.)


下一篇:老杨亲述:从事网工这8年,我曾后悔过……