看了别人的自己才有点思路,我的应该是最简单易懂的了,就是感觉没用上第二季的知识
package com.dadazuche;
public class CarStore {
private String name;
private int jine;
private int zairenliang;
private int zaihuoliang;
public CarStore(String name,int jine,int zairenliang,int zaihuoliang) {
this.name=name;
this.jine=jine;
this.zairenliang=zairenliang;
this.zaihuoliang=zaihuoliang;
}
public String getname() {
return name;
}
public int getjine() {
return jine;
}
public int getzairenliang() {
return zairenliang;
}
public int getzaihuoliang() {
return zaihuoliang;
}
}
package com.dadazuche;
import java.util.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum=0;
int zzhl=0;
int zzkl=0;
CarStore[] CarList= {
new CarStore("奥迪",2000,5,0),
new CarStore("宝马",2500,5,0),
new CarStore("五菱宏光",800,12,0),
new CarStore("法拉利",8000,2,0),
new CarStore("小卡车",2000,0,5),
new CarStore("大卡车",5000,0,15),
};
System.out.println("欢迎来到达达租车,如果您想租车请按Y,不想租车请按N");
Scanner input=new Scanner(System.in);
String a=input.next();
if(a.equals("y")) {
System.out.println("序号 车名 每天租金 载人数 载货数");
for(int i=0;i<CarList.length;i++) {
System.out.println("序列号:"+i+"\t"+CarList[i].getname()
+"\t"+CarList[i].getjine()
+"\t"+CarList[i].getzairenliang()
+"\t"+CarList[i].getzaihuoliang());
}
System.out.println("请输入需要的车辆数:");
int b=input.nextInt();
for(int c=1;c<=b;c++) {
System.out.println("请输入第"+c+"辆车的序号");
int d=input.nextInt();
switch(d){
case 0:
sum+=2000;
zzhl+=0;
zzkl+=5;
break;
case 1:
sum+=2500;
zzhl+=0;
zzkl+=5;
break;
case 2:
sum+=800;
zzhl+=0;
zzkl+=12;
break;
case 3:
sum+=8000;
zzhl+=0;
zzkl+=2;
break;
case 4:
sum+=2000;
zzhl+=5;
zzkl+=0;
break;
case 5:
sum+=5000;
zzhl+=15;
zzkl+=0;
}
}
System.out.println("请输入租车天数:");
int e=input.nextInt();
sum=sum*e;
System.out.println("总金额为:"+sum+"\n"+"总载货量:"+zzhl+"\n"+"总载客量:"+zzkl);
}
}
}