package com.imooc;
public class Che {
private String carName;
private int carPrice;
private int carPCapacity;
private int carGCapacity;
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}
public int getCarPrice() {
return carPrice;
}
public void setCarPrice(int carPrice) {
this.carPrice = carPrice;
}
public int getCarPCapacity() {
return carPCapacity;
}
public void setCarPCapacity(int carPCapacity) {
this.carPCapacity = carPCapacity;
}
public int getCarGCapacity() {
return carGCapacity;
}
public void setCarGCapacity(int carGCapacity) {
this.carGCapacity = carGCapacity;
}
}
package com.imooc;
public class HuoChe extends Che {
private int carPCapacity;
public HuoChe(String carName, int carPrice ,int carGCapacity) {
this.setCarName(carName);
this.setCarPrice(carPrice);
this.setCarPCapacity();
this.setCarGCapacity(carGCapacity);
}
public int getCarPCapacity() {
return carPCapacity;
}
public void setCarPCapacity() {
this.carPCapacity = 0;
}
}
package com.imooc;
public class KeChe extends Che {
private int carGCapacity;
public KeChe(String carName, int carPrice, int carPCapacity) {
this.setCarName(carName);
this.setCarPrice(carPrice);
this.setCarPCapacity(carPCapacity);
this.setCarGCapacity();
}
public int getCarGCapacity() {
return carGCapacity;
}
public void setCarGCapacity() {
this.carGCapacity = 0;
}
}
package com.imooc;
public class PiKa extends Che {
public PiKa(String carName, int carPrice, int carPCapacity, int carGCapacity) {
this.setCarName(carName);
this.setCarPrice(carPrice);
this.setCarPCapacity(carPCapacity);
this.setCarGCapacity(carGCapacity);
}
}
package com.imooc;
import java.util.Scanner;
public class Test {
static KeChe k1 = new KeChe("奥迪A4", 500, 4);
static KeChe k2 = new KeChe("马自达6", 400, 4);
static KeChe k3 = new KeChe("金龙", 800, 20);
static HuoChe h1 = new HuoChe("松花江", 400, 4);
static HuoChe h2 = new HuoChe("依维柯", 1000, 20);
static PiKa p1 = new PiKa("皮卡雪6", 450, 4 ,2);
static Che[] ches = {null, k1, k2, k3, h1, h2, p1};
private static int totalPrice = 0;
private static int totalPCapacity = 0;
private static int totalGCapacity = 0;
public static void main(String[] args) {
Test test = new Test();
boolean boo = true;
System.out.println("欢迎使用嗒嗒租车系统");
for( ; boo; ) {
System.out.println("1.进入系统\n2.退出系统");
Scanner system = new Scanner(System.in);
int str = system.nextInt();
if(str == 1) {
System.out.println("您可租用的车辆信息如下");
System.out.println("序号\t车名\t租金(元/天)\t载人(人)\t载货(吨)");
test.printCarInfo();
System.out.println("请输入您想租用车辆的数目");
int rentNum = new Scanner(System.in).nextInt();
Che[] totalChe = new Che[rentNum + 1];
totalChe[0] = null;
for(int num = 0; num < rentNum; num++) {
System.out.println("请输入第 " + (num + 1) + " 辆车的序号\t");
int carNo = new Scanner(System.in).nextInt();
totalChe[(num + 1)] = ches[carNo];
totalPrice = totalPrice + ches[carNo].getCarPrice();
totalPCapacity = totalPCapacity + ches[carNo].getCarPCapacity();
totalGCapacity = totalGCapacity + ches[carNo].getCarGCapacity();
}
System.out.println("请输入租用天数");
int rentDay = new Scanner(System.in).nextInt();
System.out.println("您租用的车辆信息如下");
System.out.println("序号\t车名\t租金(元/天)\t载人(人)\t载货(吨)");
for(int i = 1; i < rentNum + 1; i++) {
System.out.print(i + "\t");
System.out.print(totalChe[i].getCarName() + "\t");
System.out.print(totalChe[i].getCarPrice() + "\t\t");
System.out.print(totalChe[i].getCarPCapacity() + "\t");
System.out.print(totalChe[i].getCarGCapacity() + "\t");
System.out.println();
}
System.out.println("总租金为 " + totalPrice * rentDay + " 元");
System.out.println("可载人数为 " + totalPCapacity + " 人");
System.out.println("可载货物为 " + totalGCapacity + " 吨");
boo = false;
} else if(str == 2){
System.out.println("很遗憾,期待您的下次使用");
boo = false;
} else {
System.out.println("您的输入有误,请重新输入");
}
}
}
public void printCarInfo() {
for(int i = 1; i < ches.length; i++) {
System.out.print(i + "\t");
System.out.print(ches[i].getCarName() + "\t");
System.out.print(ches[i].getCarPrice() + "\t\t");
System.out.print(ches[i].getCarPCapacity() + "\t");
System.out.print(ches[i].getCarGCapacity() + "\t");
System.out.println();
}
}
}