package test;
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
// 用户输入需要租车的类型和天数
// 系统返回总价格
Scanner input = new Scanner(System.in);
System.out.println("----欢迎来到协同汽车租赁公司-----");
System.out.println("请选择车辆类型:1.轿车 2.客车");
int autoType = input.nextInt();
if (autoType == 1)
{
Car car = new Car();
System.out.println("请选择轿车的品牌:1.宝马 2.别克");
int brand = input.nextInt();
car.setBrand(brand);
if (brand == 1)
{
System.out.println("请选择宝马的类型:1.X6 2.550i");
} else
{
System.out.println("请选择别克的类型:1.林荫大道 2.GL8");
}
int type = input.nextInt();
car.setType(type);
car.setRentPrice();
System.out.println("请输入您需要租的天数:");
int days = input.nextInt();
RentCompany rc = new RentCompany();
rc.pay(car, days);
}
if (autoType == 2)
{
Bus bus = new Bus();
System.out.println("请选择轿车的品牌:1.金龍 2.金杯");
int brand = input.nextInt();
bus.setBrand(brand);
if (brand == 1)
{
System.out.println("请选择金龍的类型:1.16座 2.34座");
} else
{
System.out.println("请选择金杯的类型:1.16座 2.34座");
}
int type = input.nextInt();
bus.setType(type);
bus.setRentPrice();
System.out.println("请输入您需要租的天数:");
int days = input.nextInt();
RentCompany rc = new RentCompany();
rc.pay(bus, days);
}
}
}
package test;
public class Bus extends Auto
{
// private int seatNumber;
//
// public int getSeatNumber()
// {
// return seatNumber;
// }
//
// public void setSeatNumber(int seatNumber)
// {
// this.seatNumber = seatNumber;
// }
private String type;
public String getType()
{
return type;
}
public void setType(int type)
{
if (getBrand().equals("金龍"))
{
if (type == 1)
{
this.type = "16座";
} else
{
this.type = "34座";
}
} else
{
if (type == 1)
{
this.type = "16座";
} else
{
this.type = "34座";
}
}
}
@Override
public void setRentPrice()
{
if (getBrand().equals("金杯"))
{
if (this.getType().equals("16座"))
{
this.setPrice(800);
this.setNo("京6566754");
} else
{
this.setPrice(1500);
this.setNo("京9696996");
}
} else
{
if (this.getType().equals("16座"))
{
this.setPrice(800);
this.setNo("京8696997");
} else
{
this.setPrice(1500);
this.setNo("京8696998");
}
}
}
}
package test;
public class Car extends Auto
{
private String type;
public String getType()
{
return type;
}
public void setType(int type)
{
if (getBrand().equals("宝马"))
{
if (type == 1)
{
this.type = "X6";
} else
{
this.type = "550i";
}
} else
{
if (type == 1)
{
this.type = "林荫大道";
} else
{
this.type = "GL8";
}
}
}
@Override
public void setRentPrice()
{
if (getBrand().equals("宝马"))
{
if(this.getType().equals("X6"))
{
this.setPrice(800);
this.setNo("京NY28588");
}
else
{
this.setPrice(600);
this.setNo("京CNY3284");
}
} else
{
if(this.getType().equals("林荫大道"))
{
this.setPrice(300);
this.setNo("京NT37465");
}
else
{
this.setPrice(600);
this.setNo("京NT96968");
}
}
}
}
package test;
public class RentCompany
{
public void pay(Auto auto, int days)
{
int sum = auto.getPrice() * days;//租金*天数
if (auto instanceof Car)//通过判断输入的车型判断是否属于Car类
{
if (days > 0)
{
if (days > 7 && days <= 30)
{
sum = (int) (sum * 0.9);
} else if (days > 30 && days <= 150)
{
sum = (int) (sum * 0.8);
} else if (days > 150)
{
sum = (int) (sum * 0.7);
}
}
String brand = auto.getBrand();//品牌
String type = ((Car) auto).getType();//型号
if (auto instanceof Car)
System.out.println("您选择了" + brand + type + ",车牌为"
+ auto.getNo() + ",日租金为" + auto.getPrice()
+ ",优惠后您需要支付" + sum + "元");
} else
{
if (days > 0)
{
if (days >= 3 && days < 7)
{
sum = (int) (sum * 0.9);
} else if (days >= 7 && days < 30)
{
sum = (int) (sum * 0.8);
} else if (days >= 30 && days < 150)
{
sum = (int) (sum * 0.7);
} else if (days >= 150)
{
sum = (int) (sum * 0.6);
}
}
String brand = auto.getBrand();
String type = ((Bus) auto).getType();
System.out.println("您选择了" + brand + type + ",车牌为" + auto.getNo()
+ ",日租金为" + auto.getPrice() + ",优惠后您需要支付" + sum + "元");
}
}
}
package test;
import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
// 用户输入需要租车的类型和天数
// 系统返回总价格
Scanner input = new Scanner(System.in);
System.out.println("----欢迎来到协同汽车租赁公司-----");
System.out.println("请选择车辆类型:1.轿车 2.客车");
int autoType = input.nextInt();
if (autoType == 1)
{
Car car = new Car();
System.out.println("请选择轿车的品牌:1.宝马 2.别克");
int brand = input.nextInt();
car.setBrand(brand);
if (brand == 1)
{
System.out.println("请选择宝马的类型:1.X6 2.550i");
} else
{
System.out.println("请选择别克的类型:1.林荫大道 2.GL8");
}
int type = input.nextInt();
car.setType(type);
car.setRentPrice();
System.out.println("请输入您需要租的天数:");
int days = input.nextInt();
RentCompany rc = new RentCompany();
rc.pay(car, days);
}
if (autoType == 2)
{
Bus bus = new Bus();
System.out.println("请选择轿车的品牌:1.金龍 2.金杯");
int brand = input.nextInt();
bus.setBrand(brand);
if (brand == 1)
{
System.out.println("请选择金龍的类型:1.16座 2.34座");
} else
{
System.out.println("请选择金杯的类型:1.16座 2.34座");
}
int type = input.nextInt();
bus.setType(type);
bus.setRentPrice();
System.out.println("请输入您需要租的天数:");
int days = input.nextInt();
RentCompany rc = new RentCompany();
rc.pay(bus, days);
}
}
}