package didi;
//父类
public abstract class Didi {
public abstract void show(int no,String name,int price,int person,int weight);
}
package didi;
//载货车类
public class CurrentCar extends Didi {
@Override
public void show(int no, String name, int price, int person, int weight) {
// TODO Auto-generated method stub
System.out.println(" "+no+". "+name+" "+price+"元/天"+" "+"***"+" "+weight+"吨");
}
}
package didi;
//载人车类
public class PassengerCar extends Didi {
@Override
public void show(int no, String name, int price, int person, int weight) {
// TODO Auto-generated method stub
System.out.println(" "+no+". "+name+" "+price+"元/天"+" "+person+"人"+" "+"***");
}
}
package didi;
//皮卡类
public class PickUp extends Didi {
@Override
public void show(int no, String name, int price, int person, int weight) {
// TODO Auto-generated method stub
System.out.println(" "+no+". "+name+" "+price+"元/天"+" "+person+"人"+" "+weight+"吨");
}
}
package didi;
import java.util.*;
//租车数目,车辆选择以及总金额
public class Rent {
int n=1;//车辆序号
int price=0; //租车金额
int weight;//载货量
int person;//载客量
Scanner input=new Scanner(System.in);
public void RentCar(){
int num=input.nextInt();//输入租用车辆数目
while(num<=0){
System.out.println("输入的数字不符合规范,请重新输入:");
num=input.nextInt();
}
//选择租用的车辆
while(num!=0){
System.out.println("***请输入您租用的第"+n+"辆车的序号***");
int no=input.nextInt();
if(no<=0||no>6)
System.out.println("您的输入有误,请输入1-6之间的数字");
else{
num--;
switch(no){
case 1:price+=500;person+=4;System.out.println("奥迪A4");break;
case 2:price+=600;weight+=20;System.out.println("金龙");break;
case 3:price+=400;person+=4;System.out.println("马自达6");break;
case 4:price+=450;person+=4;System.out.println("皮卡雪6");break;
case 5:price+=400;person+=4;weight+=10;System.out.println("松花江");break;
case 6:price+=300;weight+=30;System.out.println("依维柯");break;
default:break;
}
n++;
}
}
//合计
System.out.println("您共租"+(n-1)+"辆车"+"\t"+"总载客量为:"+person+"人"+"\t"+"总载货量为:"+weight+"吨"+"\t"+"总计"+price+"元。");
System.out.println("感谢您的使用,再见!");
}
}
//测试类
package didi;
import java.util.Scanner;
public class Initail {
static int is=0;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("***欢迎使用答答租车系统***");
System.out.println("是否使用答答租车系统:1是 0否");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1){
System.out.println("***您可租用的汽车类型及价目表***");
//打印输出列表
System.out.println("序号 汽车名称 租金 载客量 载货量");
Didi aodi=new PassengerCar();
aodi.show(1, "奥迪A4 ", 500, 4, 0);
Didi jinlong=new CurrentCar();
jinlong.show(2, "金龙 ", 600, 0, 20);
Didi mazida=new PassengerCar();
mazida.show(3, "马自达6", 400, 4, 0);
Didi pika=new PickUp();
pika.show(4, "皮卡 ", 450, 4, 10);
Didi songhuajiang=new PassengerCar();
songhuajiang.show(5, "松花江 ", 400, 4, 0);
Didi yiweike=new CurrentCar();
yiweike.show(6, "依维柯 ", 300, 0, 30);
System.out.println("***请输入您要租用车辆的数目***");
Rent zu=new Rent();
zu.RentCar(); //选择租车数目、租车类别,输出总金额
} else if(a==0){
System.out.println("欢迎您下次光临!");
} else{
System.out.println("输入错误,请重新输入!");
}
}
}