package imooc;
import java.util.Scanner;
public class Car {
static Scanner input=new Scanner(System.in);
static carType[] car=new carType[6]; //carType数组存放各种车辆的信息
public static void main(String[] args) {
car[0]=new carPerson(1,"奥迪A4",500,4);
car[1] =new carPerson(2,"马自达6",400,4);
car[2] =new carPG(3,"皮卡雪6",450,4,2);
car[3] =new carPerson(4,"金龙",800,20);
car[4] =new carGood(5,"松花江",400,4);
car[5] =new carGood(6,"依维柯",1000,20);
System.out.println("欢迎使用答答租车系统");
System.out.println("您是否要租车:1->是 2->否");
int choice=input.nextInt();
System.out.println();
switch(choice)
{
case 1:show();break;
case 2:return;
default:System.out.println("输入有误!");
}
}
public static void show()
{
int i=0;
int[] carid=new int[6]; //carid数组记录需租车辆的车序号
int price=0; //price记录租金
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("请输入您要租车的数量:");
int num=input.nextInt();
while(i<num)
{
System.out.print("请输入第"+(i+1)+"辆车的序号:");
carid[i]=input.nextInt();
price+=car[carid[i++]-1].Rent; //计算租金
}
System.out.print("请输入租车天数:");
int day=input.nextInt(); //day记录所租的天数
System.out.println("**********");
System.out.println("您的账单");
System.out.print("可载人的车有:");
for(int j=0;j<num;j++)
if(car[carid[j]-1].Id<5)
System.out.print(car[carid[j]-1].Name+"\t");
System.out.println();
System.out.print("可载货的车有:");
for(int k=0;k<num;k++)
{
if(car[carid[k]-1].Id>4 || car[carid[k]-1].Id==3)
System.out.print(car[carid[k]-1].Name+"\t");
}
System.out.println();
System.out.println("租车总价格为:"+price*day);
}
}
class carType //父类车辆
{
int Id; //车序号
String Name; //车名
int Rent; //租金
int PersonCapacity; //载人容量
int GoodCapacity; //载货容量
}
class carPerson extends carType //子类载人车辆
{
public carPerson(int id,String name,int rent,int personCapacity)
{
this.Id=id;
this.Name=name;
this.Rent=rent;
this.PersonCapacity=personCapacity;
}
}
class carGood extends carType //子类载货车辆
{
public carGood(int id,String name,int rent,int GoodCapacity)
{
this.Id=id;
this.Name=name;
this.Rent=rent;
this.GoodCapacity=GoodCapacity;
}
}
class carPG extends carType //子类载人并载货车辆
{
public carPG(int id,String name,int rent,int personCapacity,int GoodCapacity)
{
this.Id=id;
this.Name=name;
this.Rent=rent;
this.PersonCapacity=personCapacity;
this.GoodCapacity=GoodCapacity;
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章