//创建一个父类
public class Car {
String name;//车名
int rent;//租金
int manned;//载人量
int light;//载货量
}
//创建一个子类1
public class lightCar extends Car {
//创建有参构造器
public lightCar(String name,int rent,int light){
this.name=name;//车名
this.rent=rent;//租金
this.light=light;//载货量
}
}
//创建一个子类2
public class personCar extends Car {
//创建有参构造器
public personCar(String name,int rent,int manned){
this.name=name;//车名
this.rent=rent;//租金
this.manned=manned;//载人量
}
}
//创建一个子类3
public class lightCar extends Car {
//创建有参构造器
public lightCar(String name,int rent,int light){
this.name=name;//车名
this.rent=rent;//租金
this.light=light;//载货量
}
}
//创建一个子类4
public class pickCar extends Car {
//创建有参构造器
public pickCar(String name,int rent,int manned,int light){
this.name=name;//车名
this.rent=rent;//租金
this.manned=manned;//载人量
this.light=light;//载货量
}
}
//创建一个测试类
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
personCar car1=new personCar("奥迪A4", 500, 5);
personCar car2=new personCar("马自达", 400, 5);
personCar car3=new personCar("金龙", 800, 20);
lightCar car4=new lightCar("松花江",450,2);
lightCar car5=new lightCar("依维柯",450,20);
pickCar car6=new pickCar("皮卡雪",600,2,2);
System.out.println("欢迎来到答答租车");
System.out.println("租车请输入1,退出系统请输入0");
Scanner input = new Scanner(System.in);
boolean b=true;
while (b) {
int num=input.nextInt();
switch (num) {
case 1:
System.out.println("您可选车辆类型");
System.out.println("请选择车辆序号");
System.out.println("序号/t车名/t租金/t载人量/t载货量");
System.out.println("1\t"+car1.name+"\t"+car1.rent+"元/天\t"+car1.manned+"人\t");
System.out.println("2\t"+car2.name+"\t"+car2.rent+"元/天\t"+car2.manned+"人\t");
System.out.println("3\t"+car3.name+"\t"+car3.rent+"元/天\t"+car3.manned+"人\t");
System.out.println("4\t"+car4.name+"\t"+car4.rent+"元/天\t"+0+"人\t"+car4.light+"吨\t");
System.out.println("5\t"+car5.name+"\t"+car5.rent+"元/天\t"+0+"人\t"+car5.light+"吨\t");
System.out.println("6\t"+car6.name+"\t"+car6.rent+"元/天\t"+car6.manned+"人\t"+car6.light+"吨\t");
System.out.println("请选择租车数量");
int sum=input.nextInt();
int rent=0;
int manned=0;
int light=0;
String name1="";//载人车名
String name2="";//载货车名
String name3="";//载人/货车名
for(int i=1;i<=sum;i++){
System.out.println("请输入第"+i+"辆车的序号");
int score = input.nextInt();//租车序号
switch(score){
case 1:
name1+=car1.name;
rent += car1. rent;
manned += car1.manned;
break;
case 2:
name1+=car2.name;
rent += car2.rent;
manned += car2.manned;
break;
case 3:
name1+=car3.name;
rent += car3. rent;
manned += car3.manned;
break;
case 4:
name2+=car4.name;
rent += car4. rent;
light += car4.light;
break;
case 5:
name2+=car5.name;
rent += car5. rent;
light += car5.light;
break;
case 6:
name3+=car6.name;
rent += car6. rent;
manned += car6.manned;
light += car6.light;
break;
}
}
System.out.println("请输入租车天数");
int day = input.nextInt();//租车天数
System.out.println("您的账单:");
System.out.println("载人车:"+name1);
System.out.println("载货车:"+name2);
System.out.println("皮卡车:"+name3);
System.out.println("租金:"+rent*day+"元\t载货:"+light+"吨\t载人:"+manned+"人");
break;
case 0:
System.out.println("退出系统");
b=false;
default:
System.out.println("输入错误,请提示输入");
continue;
}
}
}
}
车辆类型数量还没写好
共同学习,写下你的评论
评论加载中...
作者其他优质文章