1.要求
- 首先是一个欢迎语句
- 选择要租赁的车型
- 给出车的类型以及单天租赁价格
- 用户选择车辆编号
- 用户输入租赁天数
- 计算总金额
2.实现过程
1.创建实体类存放数据
package entity;
public class Cars {
private String id;
private String name;
private int price;
public Cars() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Cars( String id,String name, int price) {
this.id = id;
this.name = name;
this.price = price;
}
}
package entity;
package entity;
public class HCar extends Cars {
private int cargoCapacity;
public HCar() {
}
public HCar(String id,String name, int price, int cargoCapacity) {
super( id,name, price);
this.cargoCapacity=cargoCapacity;
}
public int getCargoCapacity() {
return cargoCapacity;
}
public void setCargoCapacity(int cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}
}
package entity;
public class KCar extends Cars {
private int busload;
public KCar() {
}
public KCar(String id, String name, int price, int busload) {
super(id,name, price);
this.busload = busload;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
}
package entity;
public class PCar extends KCar {
private int cargoCapacity;
public PCar() {
}
public PCar( String id,String name, int price,int busload, int cargoCapacity) {
super(id,name,price,busload);
this.cargoCapacity=cargoCapacity;
}
public int getCargoCapacity() {
return cargoCapacity;
}
public void setCargoCapacity(int cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}
}
2.创建工具类进行车辆信息操作
package utils;
import entity.HCar;
import entity.KCar;
import entity.PCar;
public class DaDaUtils {
private DaDaUtils(){
}
public static KCar[] getKCarsData(){
KCar[] kcs={
new KCar("1","K1023",120,15),
new KCar("2","K2046",140,20),
new KCar("3","K3527",180,25),
};
return kcs;
}
public static HCar[] getHCarsData(){
HCar[] hcs={
new HCar("1","h0972",140,15),
new HCar("2","h1325",100,10),
new HCar("3","h2314",120,20),
};
return hcs;
}
public static PCar[] getPCarsData(){
PCar[] pcs={
new PCar("1","p0972",160,15,10),
new PCar("2","p1325",100,10,15),
new PCar("3","p2314",120,20,15),
};
return pcs;
}
}