package com.company.Pojo;
public class Car {//汽车类父类
protected int id;//汽车编号
protected String brand;//品牌
protected double price;//租用价格
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public void show(){
System.out.println("汽车是交通工具有运输的功能");
}
}
package com.company.Pojo;
//???
public class PassengerCar extends Car {
protected int pc;//载客量
public int getPc() {
return pc;
}
public void setPc(int pc) {
this.pc = pc;
}
public PassengerCar(int id,String brand, double price, int pc) {
this.id=id;
this.brand= brand;
this.price=price;
this.pc=pc;
}
public void show(){
System.out.println(id+"\t"+brand+"\t"+price+"元/天"+"\t载客:"+pc+"人");
}
}
package com.company.Pojo;
public class PickUpCar extends Car{
private int pc;//?????
private int lc;//?????
public int getPc() {
return pc;
}
public void setPc(int pc) {
this.pc = pc;
}
public int getLc() {
return lc;
}
public void setLc(int lc) {
this.lc = lc;
}
//?вι?????
public PickUpCar(int id,String brand, double price, int pc,int lc){
this.id=id;
this.brand=brand;
this.price=price;
this.pc=pc;
this.lc=lc;
}
public void show(){
System.out.println(id+"\t"+brand+"\t"+price+"元/天"+"\t载客:"+pc+"人"+"\t载货:"+lc+"吨");
}
}
package com.company.Pojo;
import java.util.Scanner;
public class Run {
double count=0.0;//租用单个品牌的费用
double sum = 0.0;//计算租车总金额
int day = 0;//租用天数
int num = 0;//租用数量
Car[] car = {
new PassengerCar(1, " 兰博基尼雷文顿", 5000, 5),
new PassengerCar(2, " 双层多丽兰大巴车", 1000, 50),
new TruckCar(3, " 多利卡中型货车", 500, 15),
new TruckCar(4, " 东风雪铁龙大货车", 1000, 50),
new PickUpCar(5, " 皮卡雪皮卡车", 200, 4, 5)
};
public void run() {
System.out.println("欢迎使用哒哒租车系统");
System.out.println("请问您是否要租用车辆: 1是 0否");
Scanner input = new Scanner(System.in);
int select = input.nextInt();//是否要租车
if (!(select == 0 || select == 1)) {
System.out.println("输入错误系统自动退出");
System.exit(0);
} else if (select == 0) {
System.out.println("那么你是来搞笑的吗?");
System.exit(0);
} else {
System.out.println("感谢您使用我们的租车系统请问您需要租什么样的车呢这是我们的汽车类型以及价位表:");
}
System.out.println("序号\t汽车品牌\t\t\t租金\t容量");
for (Car car1 : car) {
car1.show();
}
System.out.println("请输入您要租车的序号");
int select1 = input.nextInt();//输入车辆id
if (!(select1 > 0 && select1 <= 5)) {
System.out.println("您输入的序号有误系统自动退出");
System.exit(0);
} else {
System.out.println("您要租的车辆为:");
for (int i = 0; i < car.length; i++) {
if (i == select1 - 1) {
car[i].show();
}
}
System.out.println("请问您需要租用的汽车数量?");
int select2 = input.nextInt();//汽车数量
if (!(select2 > 0 && select2 < 50)) {
System.out.println("您输入的辆数有误系统自动退出");
System.exit(0);
} else {
num = select2;
}
System.out.println("请问您需要租用多长时间呢?");
int select3 = input.nextInt();//租车时间
if (!(select3 > 0 || select3 < 50)) {
System.out.println("您输入的天数有误系统自动退出");
} else {
day = select3;
}
count = car[select1 - 1].price * day * num;
sum+=count;
System.out.println("您的目前的租车金额为:"+sum);
System.out.println("如果您还需要继续租用其他车辆请继续输入对应的序号,如果您已经完成租车请输入8为您结算租车金额");
int select4 = input.nextInt();
if (select4 == 8) {
System.out.println("您租的车的品牌为:" + car[select1 - 1].brand
+ "租车天数为:" + day + "天" + "租车数量为:" + num + "辆" + "租车费用为:" + count + "元");
System.exit(0);
} else if (!(select4 > 0 || select4 <= 5)) {
System.out.println("您的输入不合法系统自动退出");
System.exit(0);
} else {
System.out.println("您还要租的车辆为:");
for (int j = 0; j < car.length; j++) {
if (select4 - 1 == j) {
car[j].show();
}
}
}
System.out.println("请问您需要租用的汽车数量?");
int select5 = input.nextInt();
if (!(select5 > 0 && select5 < 50)) {
System.out.println("您输入的辆数有误系统自动退出");
System.exit(0);
} else {
num = select5;
}
System.out.println("请问您需要租用多长时间呢?");
int select6 = input.nextInt();
if (!(select6 > 0 || select6 <50)) {
System.out.println("您输入的天数有误系统自动退出");
} else {
day = select6;
}
count= car[select4 - 1].price * day * num;
sum=count+sum;
System.out.println("如果您已经完成租车请输入8为您结算租车金额");
int select7 = input.nextInt();
if (select7 == 8) {
System.out.println("您租的车的品牌为:" + car[select4 - 1].brand + "租车天数为:" + day + "天" + "租车数量为:" + num + "辆" + "总共需要支付金额为:" + count + "元");
System.out.println("您总共需要支付的租车费用为"+sum+"感谢您的惠顾谢谢光临");
}
}
}
}
package com.company.Pojo;
//货车
public class TruckCar extends Car {
private int lc;//载货量
public int getLc() {
return lc;
}
public void setLc(int lc) {
this.lc = lc;
}
//有参构造函数
public TruckCar(int id, String brand, double price, int lc) {
this.id = id;
this.brand = brand;
this.price = price;
this.lc = lc;
}
//汽车可以运输货物
public void show(){
System.out.println(id + "\t" + brand + "\t" + price + "元/天" + "\t载货:" + lc + "吨");
}
}
package com.company;
import com.company.Pojo.Car;
import com.company.Pojo.PassengerCar;
import com.company.Pojo.Run;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Run r=new Run();
r.run();
}
}