做项目要的就是最少的代码实现最多的功能,而且用最简单的知识来实现它。
------玄鉴
//父类——车。省略了set/get方法
public class Che {
private String brand;
static int day;
private int daymoney;
private int price;
public int priceAll(int day){
price= this.day*daymoney;
return price;
};
//子类轿车。省略了set/get方法
public class Car extends Che {
private String type;
@Override
public int priceAll(int day) {
return getDaymoney()*day;
}
——————————————
子类——客车。省略了set/get方法
public class Bus extends Che {
private int seat;
@Override
public int priceAll(int day) {
return getDaymoney()*day;
}
——————————
流程测试类。
public class Liucheng {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("欢迎来到汽车租赁公司");
System.out.println("请输入要租赁的天数:");
Che che = new Che();
Car car = new Car();
Bus bus = new Bus();
int sum = 0;
int aa = in.nextInt();
che.setDay(aa);
do {
System.out.println("请输入要租赁的汽车类型(1.轿车 2,客车 )");
switch (in.nextInt()) {
case 1:// 轿车
System.out.println("请你选择品牌:(1,宝马 2.别克)");
switch (in.nextInt()) {
case 1:// 宝马
car.setType("宝马550i");
car.setDaymoney(500);
System.out.println("租金为:" + car.priceAll(car.getDay()));// 验证是否设置成功
break;
case 2:// 别克
che.setBrand("别克");
System.out.println("请选择别克轿车型号:(1.别克商务舱Gl8 2.别克林荫大道)");
switch (in.nextInt()) {
case 1:// 商务
car.setType("别克商务舱Gl82");
car.setDaymoney(600);
System.out.println("租金为:" + car.priceAll(che.getDay()));
break;
case 2:// 林荫大道
car.setType("别克林荫大道");
car.setDaymoney(300);
System.out.println("租金为:" + car.priceAll(car.getDay()));
break;
default:
System.out.println("输入错误请重新输入。");
break;
}
break;
default:
System.out.println("输入错误请重新输入。");
break;
}
break;
case 2:// 客车
System.out.println("请选择座位数:");
bus.setSeat(in.nextInt());
if (bus.getSeat() >= 16) {
bus.setDaymoney(1500);
} else {
bus.setDaymoney(800);
}
System.out.println("请选择品牌:(1,金杯2.宇通)");
switch (in.nextInt()) {
case 1:
bus.setBrand("金杯");
System.out.println("租金为:" + bus.priceAll(bus.getDay()));
break;
case 2:
bus.setBrand("宇通");
System.out.println("租金为:" + bus.priceAll(che.getDay()));
break;
default:
System.out.println("输入错误请重新输入。");
break;
}
break;
default:
System.out.println("输入错误请重新输入。");
break;
}
sum = sum + car.priceAll(aa) + bus.priceAll(aa);
System.out.println("请问要继续租赁吗?");
} while (in.next().equals("y"));
System.out.println("总租金为:" + sum);
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123