package cars;
import java.util.Scanner;
public class RentMgrSys {
public static void main (String[] args) {
Car car = new Car();
car.leaseOutFlow();
}
}
class Car{
Scanner sc = new Scanner(System.in);
private String vehicleld;
private String brand;
private int perRent;
private String type;
// 创建car类定义四个私有属性,并创建相应的getter&setter
float calRent(int date) {
int price = this.getPerRent();
return (float)price*date;
}
//定义calRent方法,只用输入租赁的时长,然后在方法内通过调用getter方法获取对应车辆的perRent,返回租金。
void leaseOutFlow() {
int jud = 0;
// 设置判断点(jugment,用于和用户进行互动(用户输入的‘0’&‘1’即成为jud的值)
int date = 0;
System.out.println("1.宝马 2.别克"+"\n"+"请选择你要租赁的轿车品牌:");
// 按照题目输出要求和用户进行的互动提示。
jud = sc.nextInt();
if(jud == 1) {
// 第一个判断点,用if结构确定用户选择的汽车品牌(宝马&别克)
this.setBrand("宝马");
jud = 0;
System.out.println("1.550i 2.X6"+"\n"+"请选择你要租赁的轿车型号:");
// 按照题目输出要求和用户进行的互动提示。
jud = sc.nextInt();
// 第二个判断点如下,在已经选择了宝马时用if结构确定用户选择的汽车型号(550i&X6)
// 并且考虑到了用户选择1和2之外的选项。
if(jud != 1 && jud != 2) {
System.out.println("您选择的型号不在本公司的服务范围之内,请重新选择:");
System.out.println("1.550i 2.X6"+"\n"+"请选择你要租赁的轿车型号:");
jud = sc.nextInt();
}
if(jud == 1) {
this.setType("550i");
System.out.println("请输入您要租赁的天数:");
// 第三个判断点如下,在已经选择品牌和型号后,确定用户租赁的时长,并写入perRent
date = sc.nextInt();
if(date <= 0) {
System.out.println("您租赁的天数存在问题,请重新输入:");
date = sc.nextInt();
}
System.out.println("分配给您的车牌号是:京NY28588");
this.setPerRent(600);
}else if(jud == 2) {
//用户选择别克时同理。
this.setType("X6");
System.out.println("请输入您要租赁的天数:");
date = sc.nextInt();
if(date <= 0) {
System.out.println("您租赁的天数存在问题,请重新输入:");
date = sc.nextInt();
}
System.out.println("分配给您的车牌号是:京CNY3248");
this.setPerRent(800);
}else {
}
System.out.println("您需要支付的租赁费用是:"+this.calRent(date)+"元");
}else if(jud == 2){
this.setBrand("别克");
jud = 0;
System.out.println("1.林荫大道 2.GL8"+"\n"+"请选择你要租赁的轿车型号:");
jud = sc.nextInt();
if(jud != 1 && jud != 2) {
System.out.println("您选择的型号不在本公司的服务范围之内,请重新选择:");
System.out.println("1.林荫大道 2.GL8"+"\n"+"请选择你要租赁的轿车型号:");
jud = sc.nextInt();
}
if(jud == 1) {
this.setType("林荫大道");
System.out.println("请输入您要租赁的天数:");
date = sc.nextInt();
if(date <= 0) {
System.out.println("您租赁的天数存在问题,请重新输入:");
date = sc.nextInt();
}
System.out.println("分配给您的车牌号是:京NT37465");
this.perRent = 300;
}else if(jud == 2) {
this.setType("GL8");
System.out.println("请输入您要租赁的天数:");
date = sc.nextInt();
System.out.println("分配给您的车牌号是:京NT96968");
this.setPerRent(600);
}
System.out.println("您需要支付的租赁费用是:"+this.calRent(date)+"元");
}else {
System.out.println("你选择的汽车品牌不在本公司服务范围之内:1.重新选择 2. 退出");
jud = sc.nextInt();
if(jud == 1) {
this.leaseOutFlow();
}else {
System.exit(0);
}
}
}
public void setPerRent(int perRent) {
this.perRent = perRent;
}
public void setBrand(String brand) {
this.brand = brand;
}
public void setVehicleld(String vehicleld) {
this.vehicleld = vehicleld;
}
public String getVehicleld() {
return vehicleld;
}
public String getBrand() {
return brand;
}
public int getPerRent() {
return perRent;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
简简单单的汽车租赁系统
于 2022-10-11 19:38:21 首次发布