• 汽车租贷管理系统简单实现


    //车类

    package Vehicle;

    public abstract class Car {
        private String carId;        //车牌号
        private String brand;        //品牌
        private int rent;            //租金
        public Car() {
            super();
        }
        public Car(String carId, String brand, int rent) {
            super();
            this.carId = carId;
            this.brand = brand;
            this.rent = rent;
        }
        public String getCarId() {
            return carId;
        }
        public void setCarId(String carId) {
            this.carId = carId;
        }
        public String getBrand() {
            return brand;
        }
        public void setBrand(String brand) {
            this.brand = brand;
        }
        public int getRent() {
            return rent;
        }
        public void setRent(int rent) {
            this.rent = rent;
        }
        
        public abstract double carRent(double day);

    }
     

    1. package Vehicle;
    2. //轿车类
    3. public class Automobile extends Car{
    4. private String type; //型号
    5. public Automobile() {
    6. super();
    7. }
    8. public Automobile(String carId, String brand, int rent, String type) {
    9. super(carId, brand, rent);
    10. this.type = type;
    11. }
    12. public String getType() {
    13. return type;
    14. }
    15. public void setType(String type) {
    16. this.type = type;
    17. }
    18. @Override
    19. public double carRent(double day) {
    20. double number = this.getRent()*day;
    21. if(day>150){
    22. number=number*0.7;
    23. }else if(day>30){
    24. number=number*0.8;
    25. }else if(day>7){
    26. number = number*0.9;
    27. }
    28. return number;
    29. }
    30. }
    1. package Vehicle;
    2. //客车类
    3. public class Bus extends Car{
    4. private int seating; //座位数
    5. public Bus() {
    6. super();
    7. }
    8. public Bus(String carId, String brand, int rent, int seating) {
    9. super(carId, brand, rent);
    10. this.seating = seating;
    11. }
    12. public int getSeating() {
    13. return seating;
    14. }
    15. public void setSeating(int seating) {
    16. this.seating = seating;
    17. }
    18. @Override
    19. public double carRent(double day) {
    20. double number = this.getRent();
    21. if(day>=150){
    22. number=number*0.6;
    23. }else if(day>=30){
    24. number=number*0.7;
    25. }else if(day>=7){
    26. number = number*0.8;
    27. }else if(day>=3){
    28. number = number*0.9;
    29. }
    30. return number;
    31. }
    32. }

    -------------------------------上面在一个包里,下面在另一个包里--------------------------------------------------

    1. package Business;
    2. import Vehicle.Automobile;
    3. import Vehicle.Bus;
    4. import Vehicle.Car;
    5. public class CarBusiness {
    6. // 定义Car型数组
    7. public Car[] car=new Car[8];
    8. // 初始化
    9. public void init(){
    10. car[0]=new Automobile("京NY28588","宝马",800,"X6");
    11. car[1]=new Automobile("京CNY3284","宝马",600,"550i");
    12. car[2]=new Automobile("京NT37465","别克",300,"林荫大道");
    13. car[3]=new Automobile("京NT96968","别克",600,"GL8");
    14. car[4]=new Bus("京6566754","金杯",800,16);
    15. car[5]=new Bus("京8696997","金龙",800,16);
    16. car[6]=new Bus("京9696996","金杯",1500,34);
    17. car[7]=new Bus("京8696998","金龙",1500,34);
    18. }
    19. // 找车,根据条件,输出相对应的数(品牌,型号,座位数)
    20. public Car rentCar(String brand,String type,int seating){
    21. Car newCar=null;
    22. for(int i=0 ;i
    23. if(car[i] instanceof Automobile){
    24. Automobile car1 =(Automobile)car[i];
    25. if(car1.getBrand().equals(brand) && car1.getType().equals(type)){
    26. newCar=car1;
    27. break;
    28. }
    29. }else if(car[i] instanceof Bus){
    30. Bus bus =(Bus)car[i];
    31. if(bus.getBrand().equals(brand) && bus.getSeating()==seating){
    32. newCar=bus;
    33. break;
    34. }
    35. }
    36. }
    37. return newCar;
    38. }
    39. }
    1. package Business;
    2. //管理和测试
    3. import java.util.Scanner;
    4. import Vehicle.Car;
    5. public class CarManagement {
    6. Scanner sc = new Scanner(System.in);
    7. public void show(){
    8. CarBusiness cb = new CarBusiness();
    9. cb.init();
    10. System.out.println("----------------欢迎光临---------------------");
    11. System.out.println("请选择租车的类型:");
    12. System.out.print("1/轿车,2/客车(请选择):");
    13. int num=sc.nextInt();
    14. String brand ="";
    15. String type="";
    16. int seating=0;
    17. if(num==1){
    18. System.out.print("请选择要租车的品牌:1、别克,2、宝马:");
    19. int choose = sc.nextInt();
    20. if(choose==1){
    21. brand="别克";
    22. System.out.print("请选择汽车的型号:1、林荫大道,2、GL8:");
    23. type = (sc.nextInt()==1)?"林荫大道":"GL8";
    24. System.out.print("请输入要租车的天数:");
    25. double numb=sc.nextInt();
    26. Car car = cb.rentCar(brand, type, seating);
    27. System.out.println("租车成功:你的车是:");
    28. System.out.println("车牌号:"+cb.rentCar(brand, type, seating).getCarId()+"\t品牌:"+cb.rentCar(brand, type, seating).getBrand()+
    29. "\t型号:"+type);
    30. System.out.println("你需要支付"+car.carRent(numb)+"元");
    31. }else if(choose==2){
    32. brand="宝马";
    33. System.out.print("请选择汽车的型号:1、X6,2、550i:");
    34. type = (sc.nextInt()==1)?"X6":"550i";
    35. System.out.print("请输入要租车的天数:");
    36. Car car = cb.rentCar(brand, type, seating);
    37. double numb=sc.nextInt();
    38. System.out.println("租车成功:你的车是:");
    39. System.out.println("车牌号:"+cb.rentCar(brand, type, seating).getCarId()+"\t品牌:"+cb.rentCar(brand, type, seating).getBrand()+
    40. "\t型号:"+type);
    41. System.out.println("你需要支付"+car.carRent(numb)+"元");
    42. }
    43. }else if(num==2){
    44. type="";
    45. System.out.print("请选择要租车的品牌:1、金杯,2、金龙:");
    46. brand=sc.nextInt()==1?"金杯":"金龙";
    47. System.out.print("请选择汽车的座位数:1、16座,2、34座:");
    48. seating = sc.nextInt()==1?16:34;
    49. System.out.print("请输入要租车的天数:");
    50. double numb=sc.nextInt();
    51. Car car = cb.rentCar(brand, type, seating);
    52. System.out.println("租车成功:你的车是:");
    53. System.out.println("车牌号:"+cb.rentCar(brand, type, seating).getCarId()+"\t品牌:"+cb.rentCar(brand, type, seating).getBrand()+
    54. "\t座位数:"+seating);
    55. System.out.println("你需要支付"+car.carRent(numb)+"元");
    56. }else{
    57. System.out.println("你的输入有误,已退出");
    58. }
    59. }
    60. public static void main(String[] args) {
    61. CarManagement cm=new CarManagement();
    62. cm.show();
    63. }
    64. }

  • 相关阅读:
    提升APP的用户体验的方法
    Linux网络基础
    CodeTON Round 3 (Div. 1 + Div. 2, Rated, Prizes!) C. Complementary XOR
    AI:77-基于深度学习的工业缺陷检测
    JS每晚24:00更新某方法
    【MATLAB】安装 shared_slreportgen_reportexplorer_common 时检测到以下错误
    【Linux网络】工作环境救急——关于yum安装的5个花式操作
    队列 + 宽搜(BFS)
    python 微信小程序 英语单词小程序代码分享
    java基础 IO
  • 原文地址:https://blog.csdn.net/fool_Java/article/details/126263833