package java_test;
/**
* @author : Liangll
* @time : 2018/5/1 17:15
*/
import java.util.*;
class Car {
int number,personCapacity;
String brand;
double fee,goodCapacity;
public Car(int number, String brand, double fee) {
this.number = number;
this.brand = brand;
this.fee = fee;
}
public int getNumber() {
return number;
}
public String getBrand() {
return brand;
}
public double getFee() {
return fee;
}
public int getPersonCapacity(){
return personCapacity;
}
public double getGoodCapacity(){
return goodCapacity;
}
}
class PassengerCar extends Car{
private int personCapacity;
public PassengerCar(int number,String brand,double fee,int personCapacity){
super(number,brand,fee);
this.personCapacity = personCapacity;
}
@Override
public int getPersonCapacity(){
return personCapacity;
}
@Override
public String toString(){
return number + "\t" + brand + "\t" + fee + "/天\t" + personCapacity + "人\n";
}
}
class Goods extends Car{
private double goodCapacity;
public Goods(int number,String brand,double fee,double goodCapacity){
super(number,brand,fee);
this.goodCapacity = goodCapacity;
}
@Override
public double getGoodCapacity(){
return goodCapacity;
}
@Override
public String toString(){
return number + "\t" + brand + "\t" + fee + "/天\t" + goodCapacity + "吨\n";
}
}
class Loader extends Car{
private int personCapacity;
private double goodCapacity;
public Loader(int number,String brand,double fee,int personCapacity,double goodCapacity){
super(number,brand,fee);
this.personCapacity = personCapacity;
this.goodCapacity = goodCapacity;
}
@Override
public int getPersonCapacity(){
return personCapacity;
}
@Override
public double getGoodCapacity(){
return goodCapacity;
}
@Override
public String toString(){
return number + "\t" + brand + "\t" + fee + "/天\t" + personCapacity + "人" + goodCapacity + "吨\n";
}
}
public class TestCars {
public static void main(String[] args){
System.out.println("您好!欢迎来到二胖汽车租赁系统。");
System.out.println("请选择是否租车:0、是 1、否");
Scanner input = new Scanner(System.in);
Car[] cars = new Car[6];
int choice = input.nextInt();
if(choice == 0){
System.out.println("下面是所有车的信息");
System.out.println("序号\t" + "汽车名称\t" + "租金\t\t" + "容量(载人/载货)");
cars[0] = new PassengerCar(1,"奥迪A4",500.0,4);
cars[1] = new PassengerCar(2,"马自达6",400.0,4);
cars[2] = new Loader(3,"皮卡雪6",450.0,4,2.0);
cars[3] = new PassengerCar(4,"金龙",800.0,20);
cars[4] = new Goods(5,"松花江",400.0,4.0);
cars[5] = new Goods(6,"依维柯",1000.0,20.0);
for(int i = 0;i < cars.length;i++){
System.out.println("编号:" + cars[i].getNumber() + " 品牌:" + cars[i].getBrand() + " 租金:" + cars[i].getFee()
+ "/天 载客量:" + cars[i].getPersonCapacity() + "人 载货量" + cars[i].getGoodCapacity()
+ "吨");
}
}
else{
System.out.println("您已取消租车,退出系统! ");
return;
}
System.out.println("请输入您要租几种车:");
int [] choiceCars = new int[6];
//接收需要租几种车的值
int carNum = input.nextInt();
for(int i = 1;i <= carNum;i++){
System.out.println("请输入您选择的第 " + i + " 种车型的编号:" );
//接收用户选择车型的编号
int num = input.nextInt() - 1;
System.out.println(cars[num].getBrand() + " 总共需要多少辆:");
//每一种类型的车需要的数量
int num2 = input.nextInt();
//choiceCars数组表示用户选择的车型编号以及对应需要租的数量
choiceCars[num] = num2;
}
System.out.println("请输入租车天数:");
int daysNum = input.nextInt();
System.out.println("您的账单:--------------------------");
double total = 0;
for(int i = 0;i < cars.length;i++){
if(choiceCars[i] != 0){
System.out.println(choiceCars[i] + "辆" + cars[i].getBrand() + " 总共载客量:" +
choiceCars[i] * cars[i].getPersonCapacity() + "人" +
" 总共载货量:" + choiceCars[i] * cars[i].getGoodCapacity() + "吨" +
" " + daysNum + "天单项费用:" + choiceCars[i] * cars[i].getFee() * daysNum + "元");
total += choiceCars[i] * cars[i].getFee() * daysNum;
}
}
System.out.println("租车总费用:" + total + "元");
System.out.println("欢迎下次光临------------------------");
}
}
汽车租赁系统(java实现)
于 2018-05-05 16:43:27 首次发布