汽车租赁系统V1.0
首先是做题要求
以下是代码和思路
我用的是idea,需创建一个Car类和一个RentMgrSys类
代码如下
Car类
package cars;
public class Car {
private String vehicleId;
private String brand;
private String type;
private int perRent;
public Car() {
}
public Car(String vehicleId, String brand, String type, int perRent) {
this.vehicleId = vehicleId;
this.brand = brand;
this.type = type;
this.perRent = perRent;
}
public String getVehicleId() {
return vehicleId;
}
public void setVehicleId(String vehicleId) {
this.vehicleId = vehicleId;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPerRent() {
return perRent;
}
public void setPerRent(int perRent) {
this.perRent = perRent;
}
public float calRent(int days){
float money;
if(days > 150) {
money = getPerRent() * days * 7 / 10;
}else if(days > 30){
money = getPerRent() * days * 8 / 10;
}else if(days >7) {
money = getPerRent() * days * 9 / 10;
}else
money = getPerRent() * days;
return money;
}
public void leaseOutFlow(){
}
}
RentMgrSys类
package cars;
import java.util.Scanner;
public class RentMgrSys {
public static void main(String[] args) {
Car car;
String vehicleId, type, brand;
int days;
Scanner sc = new Scanner(System.in);
System.out.print("请选择你要租赁的汽车类型:");
vehicleId = sc.next();
System.out.println("1.宝马 2.别克");
System.out.print("请选择你要租赁的轿车品牌:");
brand = sc.next();
if("1".equals(brand)){
System.out.println("1.550i 2.X6");
System.out.print("请选择你要租赁的轿车型号:");
type = sc.next();
if("1".equals(type)){
System.out.print("请输入您要租赁的天数:");
days = sc.nextInt();
System.out.println("分配给您的汽车牌号是: 京CNY3284");
car = new Car(vehicleId, brand, type, 600);
System.out.print("您需要支付的租赁费用是:"+
car.calRent(days)+"元");
}
else if("2".equals(type)){
System.out.print("请输入您要租赁的天数:");
days = sc.nextInt();
System.out.println("分配给您的汽车牌号是: 京NY28588");
car = new Car(vehicleId, brand, type, 800);
System.out.print("您需要支付的租赁费用是:"+
car.calRent(days)+"元");
}
}
else if("2".equals(brand)){
System.out.println("1.林荫大道 2.GL8");
System.out.print("请选择你要租赁的轿车品牌:");
type = sc.next();
if("1".equals(type)){
System.out.print("请输入您要租赁的天数:");
days = sc.nextInt();
System.out.println("分配给您的汽车牌号是: 京NT37465");
car = new Car(vehicleId, brand, type, 300);
System.out.print("您需要支付的租赁费用是:"+
car.calRent(days)+"元。s");
}
else if("2".equals(type)){
System.out.print("请输入您要租赁的天数:");
days = sc.nextInt();
System.out.println("分配给您的汽车牌号是: 京NT96968 ");
car = new Car(vehicleId, brand, type, 600);
System.out.print("您需要支付的租赁费用是:"+
car.calRent(days)+"元");
}
}
}
}
我的运行结果为
这上面应该还有选项,由于是V1.0,老师直接截取了下面一部分,
V2.0题目如下
遇到的一些问题
1、 所以说,本题中的属性vehicleId基本没有用,只是为了V2.0做准备。
2、 我的运行结果车牌号与参考界面给出的不同,但是我觉得,根据输入的1,1,2, 2对应的是宝马X6,车牌号是京NY28588。(可能是老师出题比较随意,也可能是我理解错了)
3、 题目要求的leaseOutFlow()方法 //租车流程,我并没有用,流程都写在RentMgrSys类中的main方法中了。
总结
作为Java小白,代码水平有限,不够精简,只是做简单的分享,更多的是记录日常。