Trafalgar Law
2015-02-09 15:59
/*************************************************************************/ package 嗒嗒租车系统; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; class CAR //小汽车,只可以多载人 { private String Carname; private int Price; private int Busload; public CAR(String carname, int price, int busload) { super(); Carname = carname; Price = price; Busload = busload; } public int getBusload() { return Busload; } public void setBusload(int busload) { Busload = busload; } public String getCarname() { return Carname; } public void setCarname(String carname) { Carname = carname; } public int getPrice() { return Price; } public void setPrice(int price) { Price = price; } } class Lorry //卡车只可以多载货 { private String name; private int Price; private int Boatload; public Lorry(String name, int price, int boatload) { super(); this.name = name; Price = price; Boatload = boatload; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return Price; } public void setPrice(int price) { Price = price; } public int getBoatload() { return Boatload; } public void setBoatload(int boatload) { Boatload = boatload; } } class Pickup //皮卡车,又可以载货又可以多载人 { private String name; private int Price; private int Busload; private int Boatload; public Pickup(String name, int price, int busload, int boatload) { super(); this.name = name; Price = price; Busload = busload; Boatload = boatload; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getPrice() { return Price; } public void setPrice(int price) { Price = price; } public int getBusload() { return Busload; } public void setBusload(int busload) { Busload = busload; } public int getBoatload() { return Boatload; } public void setBoatload(int boatload) { Boatload = boatload; } } public class DADAZUZUCHE { public static void main(String[] args) { System.out.println("欢迎使用租车系统:"); Scanner input = new Scanner(System.in); System.out.println("您是否要租车?1/0(是/不是)"); try { int select = input.nextInt(); if(select==1) { System.out.println("****欢迎进入租车系统****"); System.out.println("下面是您可以租车的类型和价目表"); CarType(); Zuchenumber(); } else System.out.println("欢迎下次光临!正在退出系统...."); System.exit(5); input.close(); } catch(RuntimeException e) { throw new RuntimeException("输入的数据 类型不正确!"); } } public static void Zuchenumber() { System.out.println(); System.out.println("请输入您要租车的数量:"); Scanner input = new Scanner(System.in); int num = input.nextInt(); zucheType(num); System.out.println(); input.close(); } public static void zucheType(int num) { ArrayList<Object> al = new ArrayList<Object>(); Scanner input = new Scanner(System.in); for(int i=0;i<num;i++) { System.out.println("请输入你要租的第"+(i+1)+"车的序号:"); int number = input.nextInt(); al.add(selectCar(number)); } Arrays.asList(al); ZuCheList(al); input.close(); } private static void ZuCheList(ArrayList<Object> al) { System.out.println("请输入要租车的天数"); Scanner input = new Scanner(System.in); int day = input.nextInt(); System.out.println(); System.out.println("租车清单为:"); System.out.println(); System.out.println("\t****可以载人的车有****"); int CARload = 0; int Pickupload = 0; int ALLprice=0; for(int i=0;i<al.size();i++) { if(al.get(i)instanceof CAR) { CAR a = (CAR) al.get(i); System.out.print(a.getCarname()+" "); CARload+=a.getBusload(); ALLprice+=a.getPrice(); } if(al.get(i)instanceof Pickup) { Pickup c = (Pickup) al.get(i); System.out.print(c.getName()+" "); Pickupload+=c.getBusload(); ALLprice+=c.getPrice(); } } System.out.println("总载人数:"+(CARload+Pickupload)+"人"); System.out.println(); System.out.println(); System.out.println("****可以载货的车有****"); int LorryBoatload=0; int PKBoatload=0; for(int i=0;i<al.size();i++) { if(al.get(i)instanceof Lorry) { Lorry b = (Lorry) al.get(i); System.out.print(b.getName()+" "); LorryBoatload+=b.getBoatload(); ALLprice+=b.getPrice(); } if(al.get(i)instanceof Pickup) { Pickup c = (Pickup) al.get(i); System.out.print(c.getName()+" "); PKBoatload+=c.getBoatload(); } } System.out.println("总载货量:"+(LorryBoatload+PKBoatload)+"吨"); System.out.println(); System.out.println("****租车总价格****"+(ALLprice*day)+"元"); input.close(); } public static Object selectCar(int number) { switch(number) { case 1:return new CAR("奥迪A4",500,4); case 2:return new CAR("马自达6",400,4); case 3:return new Pickup("皮卡车",450,4,20); case 4:return new CAR("苏州金龙",800,20); case 5:return new Lorry("跃进",400,4); case 6:return new Lorry("依维柯",1000,20); default:System.out.println("您输入的车号不存在!!"); } return null; } public static void CarType() { System.out.println("序号\t\t汽车名称\t\t租金\t\t容量:"); System.out.println(); System.out.println("1\t\t奥迪A4\t\t500元/天\t\t载人:4人"); System.out.println(); System.out.println("2\t\t马自达6\t\t400元/天\t\t载人:4人"); System.out.println(); System.out.println("3\t\t皮卡车\t\t450元/天\t\t载人:4人,载货:20吨"); System.out.println(); System.out.println("4\t\t苏州金龙\t\t800元/天\t\t载人:20人"); System.out.println(); System.out.println("5\t\t跃进\t\t400元/天\t\t载货:4吨"); System.out.println(); System.out.println("6\t\t依维柯\t\t1000元/天\t载货:20吨"); } }
这个代码很棒,非常感谢
可否加注释?
大神啊,表示看不懂
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题