我吃炸土豆
2016-01-04 01:14
//主类 package package1; import java.util.Scanner; public class Main { Scanner in = new Scanner(System.in); Order o; //主菜单 public int mainMenu(){ System.out.println("欢迎使用大大租车系统!"); if(o == null){ System.out.println("检测到尚未创建账单,现在为您创建账单"); o = new Order(in); } System.out.println("1.创建新的订单"); System.out.println("2.修改已有订单"); System.out.println("3.查看订单详情"); System.out.println("其他键退出系统!"); int todo=in.nextInt(); return todo; } public static void main(String[] args) { Main m = new Main(); while(true){ int dowhat = m.mainMenu(); if (dowhat == 1){ m.o= new Order(m.in); } else if(dowhat == 2){ m.o.addVehicle(m.in); }else if(dowhat == 3) m.o.show(); else break; } } } //车类 package package1; public abstract class Vehicle { public int price; public String type; public int mount; //返回类型 public String getType(){ return type; } //返回价格 public int getPrice(){ return price; } } //卡车类 package package1; public class Truck extends Vehicle{ private int loadWeight; //初始化卡车 public Truck(String type){ this.type=type; if(type == "轻型卡车"){ this.loadWeight = 5; this.price = 1000; }else if(type == "重型卡车"){ this.loadWeight = 20; this.price = 2500; } } //返回载重 public int getWeight(){ return loadWeight; } } //客车类 package package1; public class Bus extends Vehicle{ private int loadNumber; public Bus(String type){ this.type=type; if(type == "小型客车"){ this.loadNumber = 5; this.price = 800; }else if(type == "大型客车"){ this.loadNumber = 60; this.price = 1500; } } //返回载客人数 public int getNumber(){ return loadNumber; } } //皮卡类 package package1; public class Pickup extends Vehicle{ private int loadWeight; private int loadNumber; public Pickup(String type){ this.loadWeight = 3; this.loadNumber = 15; this.type = type; } //返回载客人数 public int getNumber(){ return loadNumber; } //返回载重 public int getWeight(){ return loadWeight; } } //订单类 package package1; import java.util.Scanner; public class Order { int loadNumber; int loadWeight; int cost; Vehicle [] data = {new Truck("轻型卡车"), new Truck("重型卡车"), new Bus("小型客车"), new Bus("大型客车"),new Pickup("皮卡")}; public Order(Scanner in){ addVehicle(in); } //显示订单详情 void show(){ loadNumber=data[2].mount*((Bus)data[2]).getNumber()+ data[3].mount*((Bus)data[3]).getNumber()+ data[4].mount*((Pickup)data[4]).getNumber(); loadWeight=data[0].mount*((Truck)data[0]).getWeight()+ data[1].mount*((Truck)data[1]).getWeight()+ data[4].mount*((Pickup)data[4]).getWeight(); for(int i =0 ;i<data.length;i++){ cost+=data[i].mount*data[i].price; } System.out.println("--------------账单详情------------"); for(int i =0 ;i<data.length;i++){ System.out.println(data[i].type+" 数量:"+data[i].mount+" 单价"+data[i].price); } System.out.println("总载重:"+loadWeight+" 总载人:"+loadNumber+" 总价格:"+cost); System.out.println("--------------------------------"); } //修改订单 void addVehicle(Scanner in){ boolean quit = false; while(true){ System.out.println("选择一种以更改:"); System.out.println("1.轻型卡车 载重范围:0~5T 价格:1000元/辆"); System.out.println("2.重型卡车 载重范围:5~20T 价格:2500元/辆"); System.out.println("3.小客车 载客范围:0~5人 价格:800元/辆"); System.out.println("4.大客车 载客范围:10~60人 价格:1500元/辆"); System.out.println("5.皮卡 载重范围:0~3T 载客范围:0~15人 价格:2000/辆"); System.out.println("其他数字键退出!"); int choose = in.nextInt(); switch(choose){ case 1: System.out.println("输入数量(正数增加,负数减少):"); data[0].mount+=in.nextInt(); break; case 2: System.out.println("输入数量(正数增加,负数减少):"); data[1].mount+=in.nextInt(); break; case 3: System.out.println("输入数量(正数增加,负数减少):"); data[2].mount+=in.nextInt(); break; case 4: System.out.println("输入数量(正数增加,负数减少):"); data[3].mount+=in.nextInt(); break; case 5: System.out.println("输入数量(正数增加,负数减少):"); data[4].mount+=in.nextInt(); break; default: quit = true; break; } /* for(int i = 0;i<data.length;i++){ if(data[i].mount < 0) data[i].mount = 0; }*/ if(quit == true){ break; } } } }
建议学一下数据库,把这些东西添加到数据库中运行
Java入门第二季 升级版
530559 学习 · 6091 问题
相似问题