package good.imooc_optimise; public class AutoCar { private String name; private int price; private int capacity; private int car_no; private int capacity_g; public AutoCar(int no,String name,int price,int capacity){ this.car_no = no; this.name = name; this.price = price; this.capacity = capacity; } public AutoCar(int no,String name,int price,int capacity_p,int capacity_g){ this.car_no = no; this.name = name; this.price = price; this.capacity = capacity; this.capacity_g = capacity_g; } public int getCar_no() { return car_no; } public void setCar_no(int car_no) { this.car_no = car_no; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } public void setcapacity(int carry) { this.capacity = carry; } public int getcapacity() { return capacity; } public int getcapacity_g(){ return capacity_g; } } package good.imooc_optimise; import java.util.*; import java.util.List; public class Main { public static void main(String[] args) { // write your code here AutoCar audi = new AutoCar(1, "奥迪A4", 500, 4); AutoCar mazida = new AutoCar(2, "马自达6", 400, 4); AutoCar pika = new AutoCar(3, "皮卡雪6", 450, 4, 2); AutoCar jinlong = new AutoCar(4, "金龙", 800, 20); AutoCar songfajiang = new AutoCar(5, "松花江", 400, 4); AutoCar yiweike = new AutoCar(6, "依维柯", 1000, 20); Scanner input = new Scanner(System.in); System.out.println("欢迎使用答答租车系统:" + "\n" + "您是否要租车:1是 0否"); int input_whethear = input.nextInt(); if (input_whethear == 1) { System.out.println("你可租车的类型及其价目表:"); System.out.println("序号 " + "汽车名称 " + "租金 " + "容量 "+ "\n" +audi.getCar_no() + "." + " " + audi.getName() + " " + audi.getPrice() + "元/天" + " " + "载人:" + audi.getcapacity() + "人"+ "\n"+ +mazida.getCar_no() + "." + " " + mazida.getName() + " " + mazida.getPrice() + "元/天" + " " + "载人:" + mazida.getcapacity() + "人"+ "\n" +pika.getCar_no() + "." + " " + pika.getName() + " " + pika.getPrice() + "元/天" + " " + "载人:" + pika.getcapacity() + "人" + "载货:" + pika.getcapacity_g() + "吨"+ "\n" +jinlong.getCar_no() + "." + " " + jinlong.getName() + " " + jinlong.getPrice() + "元/天" + " " + "载人:" + jinlong.getcapacity() + "人"+ "\n" +songfajiang.getCar_no() + "." + " " + songfajiang.getName() + " " + songfajiang.getPrice() + "元/天" + " " + "载货:" + songfajiang.getcapacity_g() + "吨"+ "\n" +yiweike.getCar_no() + "." + " " + yiweike.getName() + " " + yiweike.getPrice() + "元/天" + " " + "载货:" + yiweike.getcapacity_g() + "吨"); System.out.println("请输入您要租汽车的数量:"); int AutoCar_number = input.nextInt(); int[] AutoCar_no = new int[AutoCar_number]; //List<AutoCar> listCar = new ArrayList<AutoCar>(); for(int i=0;i<AutoCar_number;i++){ System.out.println("请输入第"+(i+1)+"辆车的序号"); int num = input.nextInt(); AutoCar_no[i] = num; } System.out.println("请输入租车天数:"); int days = input.nextInt(); System.out.println("您的账单:"); int population = 0; double goods = 0.0; int total_price = 0; System.out.println("***可载人的车有:"); for (int j = 0; j < AutoCar_number; j++) { switch (AutoCar_no[j]) { case 1: System.out.print(audi.getName() + "\t"); population += 4; total_price += 500; break; case 2: System.out.print(mazida.getName() + "\t"); population += 4; total_price += 400; break; case 3: System.out.print(pika.getName() + "\t"); population += 4; goods += 2; total_price += 800; break; case 4: System.out.print(jinlong.getName() + "\t"); population += 20; total_price += 450; break; case 5: goods += 4; total_price += 400; break; case 6: goods += 20; total_price += 1000; break; } } System.out.print("共载人:" + population + "人\n"); System.out.println("***载货的车有:"); for (int j = 0; j < AutoCar_number; j++) { if (AutoCar_no[j] == 3) { System.out.print(pika.getName()); } if (AutoCar_no[j] == 5) { System.out.print(songfajiang.getName() + "\t"); } if (AutoCar_no[j] == 6) { System.out.print(yiweike.getName() + "\t"); } } System.out.println(" 载货" + goods + "吨"); System.out.print("租车的总价格:" + total_price * days); } else { if ((input_whethear == 0)) { System.out.println("感谢您的使用,谢谢!"); } else { System.out.println("输入不正确,请重写输入!"); } } } }
慕慕5436299
慕设计2395807
安浪创想
相关分类