package com.dadaZuChe;public class Car { protected int num; protected String name; protected int zuJin; public int getNum() { return num; } public void setNum(int num) { this.num = num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getZuJin() { return zuJin; } public void setZuJin(int zuJin) { this.zuJin = zuJin; } }
package com.dadaZuChe;public class KeChe extends Car { protected int zaiRenLiang; public int getZaiRenLiang() { return zaiRenLiang; } public void setZaiRenLiang(int zaiRenLiang) { this.zaiRenLiang = zaiRenLiang; } public void show() { System.out.println(num+". "+name+" "+zuJin+"元/天 "+"载人:"+zaiRenLiang+"人"); } public KeChe(int i,String name,int zj,int zairen) { this.setNum(i); this.setName(name ); this.setZuJin(zj); this.setZaiRenLiang(zairen); } public KeChe() { // TODO Auto-generated constructor stub }}
package com.dadaZuChe;public class HuoChe extends Car{ public double zaiHuoLiang; public HuoChe(int i,String name,int zj,int zaihuo) { this.setNum(i); this.setName(name ); this.setZuJin(zj); this.setZaiHuoLiang(zaihuo); } public HuoChe() { // TODO Auto-generated constructor stub } public double getZaiHuoLiang() { return zaiHuoLiang; } public void setZaiHuoLiang(double zaiHuoLiang) { this.zaiHuoLiang = zaiHuoLiang; } public void show() { System.out.println(num+". "+name+" "+zuJin+"元/天 "+"载货:"+zaiHuoLiang+"吨"); }}
package com.dadaZuChe;import java.util.Scanner;public class zuChe { public static void main(String[] args) { KeChe a=new KeChe(1,"奥迪A4",500,4); KeChe b=new KeChe(2,"马自达6",400,4); PiKa c=new PiKa(3,"皮卡雪",450,4,2); KeChe d=new KeChe(4,"金龙",800,20); HuoChe e=new HuoChe(5,"松花江",400,4); HuoChe f=new HuoChe(6,"依维柯",1000,20); System.out.println("欢迎使用答答租车系统!"); System.out.println("您是否需要租车? 1是 0否"); Scanner input=new Scanner(System.in); int in=input.nextInt(); if(in==0){ System.out.println("感谢使用本系统,再见!"); return; }else if(in==1) { System.out.println("您可租车的类型和价目表"); a.show(); b.show(); c.show(); d.show(); e.show(); f.show(); } System.out.println("请输入您要租汽车的数量"); Scanner input2=new Scanner(System.in); int number=input.nextInt(); int[] zuCheBiao=new int[number]; for(int i=0;i<number;i++) { System.out.println("请输入第"+(i+1)+"辆车的序号"); Scanner r=new Scanner(System.in); zuCheBiao[i]=r.nextInt(); } System.out.println("请输入租车天数"); Scanner r=new Scanner(System.in); int tianShu=r.nextInt(); int R=0;//载人的车数 int H=0;//载货的车数 double sumMoney=0; for(int n:zuCheBiao) { switch(n) { case 1:R++;sumMoney+=(500*tianShu);break; case 2:R++;sumMoney+=400*tianShu;break; case 3:R++;H++;sumMoney+=450*tianShu;break; case 4:R++;sumMoney+=800*tianShu;break; case 5:H++;sumMoney+=400*tianShu;break; case 6:H++;sumMoney+=1000*tianShu;break; } } int[] ZaiRenChe=new int[R]; int[] ZaiHuoChe=new int[H]; //匹配信息 载人数组 载货数组 R=0;//标记载人数 H=0; for(int n:zuCheBiao) { switch(n) { case 1:ZaiRenChe[R]=1;R++;break; case 2:ZaiRenChe[R]=2;R++;break; case 3:ZaiRenChe[R]=3;R++;ZaiHuoChe[H]=3;H++;break; case 4:ZaiRenChe[R]=4;R++;break; case 5:ZaiHuoChe[H]=5;H++;break; case 6:ZaiHuoChe[H]=6;H++;break; } } System.out.println("您的账单:"); System.out.println("***可载人的车有:"); int gongZaiRen=0; for(int n:ZaiRenChe) { switch(n) { case 1:System.out.println(" 奥迪A4");gongZaiRen+=4;break; case 2:System.out.println(" 马自达6");gongZaiRen+=4;break; case 3:System.out.println(" 皮卡雪6");gongZaiRen+=4;break; case 4:System.out.println(" 金龙");gongZaiRen+=20;break; } } System.out.println("共载人"+gongZaiRen+"人"); System.out.println("***可载货的车有:"); double gongZaiHuo=0; for(int n:ZaiHuoChe) { switch(n) { case 3:System.out.println(" 皮卡雪6");gongZaiHuo+=2;break; case 5:System.out.println(" 松花江");gongZaiHuo+=4;break; case 6:System.out.println(" 依维柯");gongZaiHuo+=20;break; } } System.out.println("共载货"+gongZaiHuo+"吨"); System.out.println("租车总价格"+sumMoney+"元"); } }