慕运维8340830
2019-10-06 17:24
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);
}
}
}
我觉你的简单易懂,我试了一下你的程序,有个不好的地方:进入租车系统提示语句,应该写成"欢迎来到达达租车,如果您想租车请输入y,不想租车请输入n",这样更易懂。
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题