//测试类
package com.System.show;
import com.leasesystem.car.*;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
int sum = 0;
int peopleSum = 0;
int goodsSum = 0;
System.out.println("您是否租车?(1:是/0:不是)");
Scanner scanner = new Scanner(System.in);
String num1 = scanner.next();
if ("1".equals(num1)) {
System.out.println("序号"+" "+"类型"+" "+"价格"+" "+"容量");
for(int i = 1;i<7;i++){
Vehicle car = Demo.showCar(i);
System.out.println(car.getId()+" "+car.getType()+" "+car.getPrice()+" "+car.getCapacity()+car.getCapaUnit());
}
for (boolean bool = true;bool == true;) {
System.out.println("请输入要租的车型(0:选车结束):");
String num2 = scanner.next();
int num2_1 = Integer.parseInt(num2);
if("0".equals(num2)){
bool = false;
}else if(num2_1 >6){
System.out.println("输入错误!重新输入");
}else{
Vehicle car = Demo.showCar(num2_1);
sum += car.getPrice();
if (car.getCapaUnit().equals("吨/辆")) {
goodsSum += car.getCapacity();
}else{
peopleSum += car.getCapacity();
}
}
}
} else {
System.out.println("谢谢光临");
}
System.out.println("租借清单:");
System.out.println("总金额:"+sum);
System.out.println("总载人量:"+peopleSum);
System.out.println("总载货量:"+goodsSum);
scanner.close();
}
private static Vehicle showCar(int i) {
switch (i) {
case 1:
{
Vehicle car = new SalooCar();
return car;
}
case 2:
{
Vehicle car = new StandardCar();
return car;
}
case 3:
{
Vehicle car = new Bus();
return car;
}
case 4:
{
Vehicle car = new Truck();
return car;
}
case 5:
{
Vehicle car = new HeavyTruck();
return car;
}
case 6:
{
Vehicle car = new Pickup();
return car;
}
default:
{
Vehicle car = new StandardCar();
return car;
}
}
}
}
//抽象car父类
package com.leasesystem.car;
public abstract class Vehicle {
int id;
String type;
int price;
int capacity;
String capaUnit;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getCapacity() {
return capacity;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public String getCapaUnit() {
return capaUnit;
}
public void setCapaUnit(String capaUnit) {
this.capaUnit = capaUnit;
}
}
//各种类型的车类
//豪华轿车类
package com.leasesystem.car;
public class SalooCar extends Vehicle {
public SalooCar(){
this.id = 1;
this.type = "豪华轿车";
this.price = 500;
this.capacity = 6;
this.capaUnit = "人/辆";
}
}
//普通汽车类
package com.leasesystem.car;
public class StandardCar extends Vehicle {
public StandardCar() {
this.id = 2;
this.type = "普通汽车";
this.price = 350;
this.capacity = 4;
this.capaUnit = "人/辆";
}
}
//客车类
package com.leasesystem.car;
public class Bus extends Vehicle {
public Bus(){
this.id = 3;
this.type = "客车";
this.price = 1000;
this.capacity = 50;
this.capaUnit = "人/辆";
}
}
//货车类
package com.leasesystem.car;
public class Truck extends Vehicle {
public Truck() {
this.id = 4;
this.type = "卡车";
this.price = 1000;
this.capacity = 5;
this.capaUnit = "吨/辆";
}
}
//重型货车类
package com.leasesystem.car;
public class HeavyTruck extends Vehicle {
public HeavyTruck() {
this.id = 5;
this.type = "重型货车";
this.price = 3000;
this.capacity = 20;
this.capaUnit = "吨/辆";
}
}
//别克车类
package com.leasesystem.car;
public class Pickup extends Vehicle {
public Pickup() {
this.id = 6;
this.type = "皮卡车";
this.price = 600;
this.capacity = 1;
this.capaUnit = "吨/辆";
}
}
添加回答
举报
0/150
提交
取消