package wang;
public class Car {
protected String carName;
protected int rentMoney;
protected int pessengersCapacity;
protected int cargoCapacity;
}
package wang;
public class Passengercar extends Car {
protected Passengercar(String carName,int rentMoney,int pessengersCapacity){
this.carName = carName;
this.rentMoney = rentMoney;
this.pessengersCapacity = pessengersCapacity;
}
@Override
public String toString() {
return " \t"+carName + "\t" + rentMoney + "元/天 \t载人:"+ pessengersCapacity+"人" ;
}
}
package wang;
public class Truck extends Car {
protected Truck(String carName,int rentMoney,int cargoCapacity){
this.carName = carName;
this.rentMoney = rentMoney;
this.cargoCapacity = cargoCapacity;
}
public String toString() {
return " \t"+carName + "\t" + rentMoney + "元/天 \t载货:"+cargoCapacity+"吨";
}
}
package wang;
public class Pickup extends Car {
protected Pickup(String carName,int rentMoney,int pessengersCapacity,int cargoCapacity){
this.carName = carName;
this.rentMoney = rentMoney;
this.pessengersCapacity = pessengersCapacity;
this.cargoCapacity = cargoCapacity;
}
public String toString() {
return " \t"+carName + "\t" + rentMoney + "元/天 \t载人:"+ pessengersCapacity+"人载货:"+cargoCapacity+"吨";
}
}
package wang;
import java.util.*;
public class initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car car[] = { new Passengercar("奥迪A4",500,4),new Passengercar("马自达6",400,4),
new Pickup("皮卡雪6",450,4,2),new Passengercar("金龙",800,20),
new Truck("松花江",400,4),new Truck("依维柯",1000,20)
};
System.out.println("欢迎使用答答租车系统:");
System.out.println("你是否要租车:1是 0否");
Scanner input = new Scanner(System.in);
if(input.nextInt() == 1){ //判断是否要进入系统
System.out.println("你可租车的类型及价目表:");
System.out.println("序号 \t汽车名称\t租金 \t容量");
for (int i = 0; i < car.length; i++) { //列出所有车型
System.out.print(i+1+".");
System.out.println(car[i]);
}
System.out.println("请输入你要租车的数量:");
int carRentNum = input.nextInt();//租车数量
int carArr[] = new int [carRentNum]; //获得租车序号并存入数组
for(int i =0; i<carRentNum;i++){
System.out.println("请输入第"+(i+1)+"辆车的序号:");
carArr[i] = input.nextInt();
}
System.out.println("请输入租车天数:");
int rentDays = input.nextInt();//租车天数
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
int totalPessengerCapacity =0;//总载人数
for(int i =0;i<carRentNum;i++){
if(car[carArr[i]-1].pessengersCapacity > 0){
totalPessengerCapacity += car[carArr[i]-1].pessengersCapacity;
System.out.print(car[carArr[i]-1].carName+" ");
}
}
System.out.println("共载人:"+totalPessengerCapacity+"人");
System.out.println("***可载货的车有:");
float totalCargoCapacity =0f;//总载货量
for(int i =0;i<carRentNum;i++){
if(car[carArr[i]-1].cargoCapacity > 0){
totalCargoCapacity += car[carArr[i]-1].cargoCapacity ;
System.out.print(car[carArr[i]-1].carName+" ");
}
}
System.out.println("共载货:"+totalCargoCapacity+"吨");
System.out.print("***租车总价格:");
float totalRentMoney = 0f; //总租金
for(int i =0;i<carRentNum;i++){
totalRentMoney += car[carArr[i]-1].rentMoney * rentDays;
}
System.out.println(totalRentMoney+"元");
}
else
System.out.println("谢谢使用答答租车系统,再见!");
}
}