package com.jun;
import java.util.Scanner;
public class Car
{
public static void main(String[] args)
{
int NumsOfRent;
int DaysOfRent;
CarType[] Cars=new CarType[4];
Cars[0]=new CarType(1,"car_1",500,4,1);
Cars[1]=new CarType(1,"car_2",300,20,2);
Cars[2]=new CarType(2,"car_3",200,5,3);
Cars[3]=new CarType(2,"car_4",600,10,4);
System.out.println("欢迎使用Jun租车系统");
System.out.println("您是否要租车 : 是 1 否 0");
Scanner scan = new Scanner(System.in);
String str=scan.next();
if(str.equals("0"))
System.out.println("欢迎下次光临");
else if(str.equals("1"))
{
System.out.println("你可以选择的车型如下:");
System.out.println("序号 车 型 租 金 容 量");
for(int i=0;i<4;i++)
Cars[i].List();
}
System.out.println("输入你需要租用的数量: ");
NumsOfRent=scan.nextInt(); //租用的车辆数
CarType[] RentCar=new CarType[NumsOfRent]; //用于存储租用车辆信息
for(int i=0;i<NumsOfRent;i++)
{
System.out.println("输入第"+(i+1)+"辆车的序号: ");
int NR=scan.nextInt();
if(NR>4)
{
System.out.println("没有此车辆");
i--;
continue;
}
RentCar[i]=Cars[NR-1];
}
System.out.println("输入租用天数: ");
DaysOfRent=scan.nextInt();
System.out.println("你的账单:");
System.out.println("************可载人的车有*************");
int cost=0;
int NumOfMan=0;
int NumOfCargo=0;
for(int i=0;i<NumsOfRent;i++)
if(RentCar[i].GetType()==1)
{
cost+=RentCar[i].GetCost()*DaysOfRent;
NumOfMan+=RentCar[i].GetM();
}
for(int i=0;i<NumsOfRent;i++)
if(RentCar[i].GetType()==1)
System.out.print(RentCar[i].GetName()+" ");
System.out.println("可载人: "+NumOfMan+"人");
System.out.println("************可载物的车有*************");
for(int i=0;i<NumsOfRent;i++)
if(RentCar[i].GetType()==2)
{
cost+=RentCar[i].GetCost()*DaysOfRent;
NumOfCargo+=RentCar[i].GetC();
}
for(int i=0;i<NumsOfRent;i++)
if(RentCar[i].GetType()==2)
System.out.print(RentCar[i].GetName()+" ");
System.out.println("可载物: "+NumOfCargo+"吨");
System.out.println("************总花费*************");
System.out.println("你共花费: "+cost+"元");
}//main
}//class
package com.jun;
public class CarType
{
private String CarName=null;
private int RentCost=0;
private int Car_Man=0;
private int Car_Cargo=0;
private int type=0; //type=1 载人 type=2 载物
private int Num;
CarType(int type,String names,int cost,int MorC ,int n)
{
CarName=names;
RentCost=cost;
this.type=type;
Num=n;
if(type==1)
Car_Man=MorC;
else if(type==2)
Car_Cargo=MorC;
}
void List()
{
if(type==1)
System.out.println(Num+" "+CarName+" "+RentCost+"元/天 载人:"+Car_Man+"人");
else if (type==2)
System.out.println(Num+" "+CarName+" "+RentCost+"元/天 载物:"+Car_Cargo+"吨");
}
public int GetType()
{
return type;
}
public String GetName()
{
return CarName;
}
public int GetCost()
{
return RentCost;
}
public int GetM()
{
return Car_Man;
}
public int GetC()
{
return Car_Cargo;
}
}
Traveler_0001
2014-10-19
举报
0/150
提交
取消