主类
import java.util.Scanner;
public class carRentSystem{
static carRentSystem mySystem = new carRentSystem();
A4 myA4 = new A4();
Maz myMaz = new Maz();
Pic myPic = new Pic();
Jin myJin = new Jin();
Son mySon = new Son();
Yiw myYiw = new Yiw();
public static void main(String[] args){
mySystem.YorN();
}
public void YorN(){
System.out.println("欢迎光临,请问您想要租车吗?\n1.是\n2.否");
Scanner myscanner = new Scanner(System.in);
int choice = myscanner.nextInt();
if(choice == 1){
choosecar();
}else{
System.out.println("非常抱歉没能帮到您,欢迎下次光临");
}
}
public void choosecar(){
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量");
System.out.println("1. 奥迪A4 500元/天 载人:4人");
System.out.println("2. 马自达6 400元/天 载人:4人");
System.out.println("3. 皮卡雪6 450元/天 载人:4人 载货:2吨");
System.out.println("4. 金龙 800元/天 载人:20人");
System.out.println("5. 松花江 400元/天 载货:4吨");
System.out.println("6. 依维柯 1000元/天 载货:20吨");
System.out.print("请输入您要租车的数量:");
Scanner myscanner = new Scanner(System.in);
int times = myscanner.nextInt();
int price = 0;
for(int i = 1;i <=times;i++){
System.out.println("请输入您要租的汽车的序号:");
int carNum = myscanner.nextInt();
switch(carNum){
case 1:
price = price + myA4.getPrice();
case 2:
price = price + myMaz.getPrice();
case 3:
price = price + myPic.getPrice();
case 4:
price = price + myJin.getPrice();
case 5:
price = price + mySon.getPrice();
case 6:
price = price + myYiw.getPrice();
}
}
System.out.println("选车完毕,这是您的账单:");
System.out.println("总价:"+price+"元");
}
}
车类格式
public class A4{
String name = "奥迪A4";
int price = 500;
public int getPrice(){
return price;
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123