租车系统
增加货车,每吨每天收费50;
增加可以选择租车数量
/**
* 父类:机动车类
* @author Administrator
*
*/
public abstract class MotoVehicle {
private String no;//车牌
private String brand;//汽车品牌
/**
* 无参构造方法
*/
public MotoVehicle() {
}
/**
* 有参构造方法
* @param no 汽车牌号
* @param brand 汽车品牌
*/
public MotoVehicle(String no,String brand) {
this.no=no;
this.brand=brand;
}
public String getNo() {
return no;
}
public String getBrand() {
return brand;
}
//抽象方法,计算租金
public abstract int calcRent(int days);
}
/**
* 子类:Car类继承MotoVehicle
* @author Administrator
*
*/
public class Car extends MotoVehicle{
private String type;//小轿车的类型
public Car() {
}
public Car (String no,String brand,String type) {
super(no,brand);
this.type=type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
/**
* 重写父类的计算租金的方法
*/
@Override
public int calcRent(int days) {
if("1".equals(type)) {
return days*500;
}
else if ("2".equals(type)) {
return days*600;
}
else {
return 300*days;
}
}
}
/**
*子类: bus类继承MotoVehicle
* @author Administrator
*
*/
public class Bus extends MotoVehicle{
private int CountSet;//客车的座位数
public Bus() {
}
/**
* 带参构造函数
*/
public Bus(String no,String brand,int CountSet) {
super(no,brand);
this.CountSet=CountSet;
}
public int getCountSet() {
return CountSet;
}
public void setCountSet(int countSet) {
CountSet = countSet;
}
/**
* 重写父类中计算租金的计算方法
*/
@Override
public int calcRent(int days) {
if(CountSet<16) {
return 800*days;
}
else {
return 1500*days;
}
}
}
/**
* 子类:Truck类继承MotoVehicle类
* @author Administrator
*
*/
public class Truck extends MotoVehicle{
private int ton;//吨数
public Truck() {
}
/**
* 带参的构造函数
* @param no
* @param brand
* @param ton
*/
public Truck(String no,String brand,int ton) {
super(no,brand);
this.ton=ton;
}
public int getTon() {
return ton;
}
public void setTon(int ton) {
this.ton = ton;
}
/**
* 重写父类的方法
*/
@Override
public int calcRent(int days) {
return 50*days*ton;
}
}
public class User {
private String id;//租车人的编号
private String name;//租车人的姓名
public User() {
}
public User(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
*计算所有车辆的总租金
* @param motos
* @param days
* @return
*/
public int calcTotalRent(MotoVehicle motos[],int days) {
int sum=0;
for(int i=0;i
public class Test {
public static void main(String[] args) {
String brand,mytype;//汽车品牌、轿车的类型
int countSet,days,n,ton;//座位数、租赁的天数、租车的总数、吨数
Scanner scan=new Scanner(System.in);
System.out.println("欢迎来到汽车租赁公司!");
System.out.println("请输入要租赁的天数:");
days=scan.nextInt();
System.out.println("请输入你要租几辆车:");
n=scan.nextInt();
MotoVehicle []motos=new MotoVehicle[n];//定义一个MotoVehicle类型的数组,长度为租车总数
for(int i=0;i