Car类
package com.imooc;
public abstract class car {
public abstract int personNum();
public abstract int storeNum();
public abstract String carId();
public abstract int money();
}
biacar类
package com.imooc;
public class Bigcar extends car {
@Override
public int personNum() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int storeNum() {
// TODO Auto-generated method stub
return 20;
}
@Override
public String carId() {
// TODO Auto-generated method stub
return "大货车";
}
@Override
public int money() {
// TODO Auto-generated method stub
return 1500;
}
bus类
```package com.imooc;
public class bus extends car {
@Override
public int personNum() {
// TODO Auto-generated method stub
return 40;
}
@Override
public int storeNum() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String carId() {
// TODO Auto-generated method stub
return "大巴车";
}
@Override
public int money() {
// TODO Auto-generated method stub
return 500;
}
}
littecar类
package com.imooc;
public class litteCar extends car {
@Override
public int personNum() {
// TODO Auto-generated method stub
return 5;
}
@Override
public int storeNum() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String carId() {
// TODO Auto-generated method stub
return "小汽车";
}
@Override
public int money() {
// TODO Auto-generated method stub
return 300;
}
}
picar
package com.imooc;
public class picar extends car {
@Override
public int personNum() {
// TODO Auto-generated method stub
return 5;
}
@Override
public int storeNum() {
// TODO Auto-generated method stub
return 3;
}
@Override
public String carId() {
// TODO Auto-generated method stub
return "皮卡";
}
@Override
public int money() {
// TODO Auto-generated method stub
return 1000;
}
}
storecar类
package com.imooc;
public class storeCar extends car {
@Override
public int personNum() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int storeNum() {
// TODO Auto-generated method stub
return 5;
}
@Override
public String carId() {
// TODO Auto-generated method stub
return "小货车";
}
@Override
public int money() {
// TODO Auto-generated method stub
return 800;
}
}
测试运行类
package com.imooc;
import java.util.*;
public class admin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("******欢迎来到哒哒租车系统*******");
System.out.println("请问您想要租车吗?");
Scanner input=new Scanner(System.in);
int str=input.nextInt();
if(str==0){
System.out.println("谢谢光临");
}
if(str==1){
System.out.println("您可以租赁的车辆为:");
//应用显示方法
admin Show=new admin();
Show.show();
//应用选择方法
admin Which=new admin();
Which.which();
//计算总金额
}
if(str!=0&&str!=1){
System.out.println("输入错误!");
}
}
public void show(){
car Bus=new bus();
car littecar=new litteCar();
car piCar=new picar();
car storecar=new storeCar();
car bigCar=new Bigcar();
System.out.println("车辆名称:"+"\t"+Bus.carId()+"\t"+littecar.carId()+"\t"+piCar.carId()+"\t"+storecar.carId()+"\t"+bigCar.carId());
System.out.println("容量/顿:"+"\t"+Bus.personNum()+"\t"+littecar.personNum()+"\t"+piCar.personNum()+piCar.storeNum()+"\t"+storecar.storeNum()+"\t"+bigCar.storeNum());
System.out.println("每天租金/元:"+Bus.money()+"\t"+littecar.money()+"\t"+piCar.money()+"\t"+storecar.money()+"\t"+bigCar.money());
}
public void which(){
car Bus=new bus();
car littecar=new litteCar();
car piCar=new picar();
car storecar=new storeCar();
car bigCar=new Bigcar();
Scanner input=new Scanner(System.in);
System.out.println("您要租赁的车辆数为:");
int num=input.nextInt();
int[] carMun=new int[num];
String[] carName=new String[num];
int[] carStore=new int[num];
int[] carPerson=new int[num];
int sumMoney=0;
int sumPerson=0;
int sumStore=0;
for(int i=1;i<=num;i++){
System.out.println("请输入第"+i+"辆车的序号");
int carNum=input.nextInt();
//carMun[i]=carNum;
switch(carNum){
case 1:
carMun[i-1]=Bus.money();
carName[i-1]=Bus.carId();
carStore[i-1]=Bus.storeNum();
carPerson[i-1]=Bus.personNum();
System.out.println(carName[i-1]);
continue;
case 2:
carMun[i-1]=littecar.money();
carName[i-1]=littecar.carId();
carStore[i-1]=littecar.storeNum();
carPerson[i-1]=littecar.personNum();
continue;
case 3:
carMun[i-1]=piCar.money();
carName[i-1]=piCar.carId();
carStore[i-1]=piCar.storeNum();
carPerson[i-1]=piCar.personNum();
continue;
case 4:
carMun[i-1]=storecar.money();
carName[i-1]=storecar.carId();
carStore[i-1]=storecar.storeNum();
carPerson[i-1]=storecar.personNum();
continue;
case 5:
carMun[i-1]=bigCar.money();
carName[i-1]=bigCar.carId();
carStore[i-1]=bigCar.storeNum();
carPerson[i-1]=bigCar.personNum();
continue;
}
/*sumMoney=sumMoney+carMun[i-1];
sumPerson=sumPerson+carPerson[i-1];
sumStore=sumStore+carStore[i-1];
System.out.println("您选择的车辆是:"+carName[i-1]);*/
}
System.out.println("请输入租车的天数:");
int day=input.nextInt();
System.out.println("您选择的车辆有:");
for(int i=0;i<num;i++){
sumMoney=(sumMoney+carMun[i]);
sumPerson=(sumPerson+carPerson[i]);
sumStore=sumStore+carStore[i];
System.out.println(carName[i]);
}
System.out.println("总载客量为:"+sumPerson+"人");
System.out.println("总载货量为;"+sumStore+"吨");
System.out.println("一共租金为:"+sumMoney*day+"元");
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦