Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize a simple car Rental system by java

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "java how to achieve a simple car rental system", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "java how to achieve a simple car rental system" this article.

The details are as follows

Welcome to xx car Rental.

Please enter a user name

Enter Your PIN

(the user name is abbreviated by default, and the password is 123. Encapsulate the login module into the method to call the method.)

Please enter your action

1) View all the vehicle information in the garage now

2) Rental car

3) add a car to the garage

4) modify car rental price information

Use switch to judge the operation

Class analysis

Code:

Package com.youjiuye.bms;public class CRMS {public static void main (String [] args) {Wellcome ();} public static void Wellcome () {System.out.println ("* *"); System.out.println ("\ t Welcome to he Boss Library") System.out.println ("* *"); / / get user information Tool.inputInfo ();}} package com.youjiuye.bms / * * functional modules of car rental system * 1, administrator add vehicle information in garage * 2, user rental vehicle * 3, user view car in garage * 4, user view vehicle leased by user * 5, administrator modifies vehicle price * 6, user settlement rent * / public class CRMSService {/ / 1, The administrator adds the vehicle information in the garage public boolean addVehicel (MotoVehicel mo) {boolean bo = false MotoVehicel [] ms = MotoVehicel.getMs (); if (ms.length > 0) {for (int I = 0; I)

< ms.length; i++) { if(ms[i] == null){ ms[i] = mo; bo = true; System.out.println("添加成功!"); break; } } } return bo; } // 2、用户租赁车辆 public void rent(Users u,MotoVehicel mo){ MotoVehicel[] ms = u.getUms(); for (int i = 0; i < ms.length; i++) { if(ms[i] == null){ ms[i] = mo; break; } } } // 4、用户查看自己租赁的车辆 public boolean browse(Users u){ boolean bo = false; MotoVehicel[] mo = u.getUms(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null){ System.out.println(mo[i].toString()); bo = true; } } } return bo; } // 5、管理员修改车辆的价格 public boolean update(String no,double price){ boolean bo = false; if(MotoVehicel.arrayExit()){ MotoVehicel[] ms = MotoVehicel.getMs(); for (int i = 0; i < ms.length; i++) { if(ms[i] != null && ms[i].getNo().equals(no)){ ms[i].setRentPrice(price); System.out.println("修改成功!"); System.out.println(ms[i]); bo = true; } } }else{ System.out.println("当前车库中还没有车辆"); } return bo; } // 6、用户结算租金 public double settleAccount(Users u,int days){ double price = 0; MotoVehicel[] mo = u.getUms(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null){ price += mo[i].getRentPrice() * days; } } } return price; } // 删除车库中的车辆 public void delete(MotoVehicel moo){ MotoVehicel[] mo = MotoVehicel.getMs(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null && mo[i].equals(moo)){ mo[i] = null; } } } } // 根据车牌号来判断车库中是否含有该车辆 public boolean judgeExitMotoVehicel(String no){ boolean bo = false; MotoVehicel[] ms = MotoVehicel.getMs(); if(ms.length >

0) {for (int I = 0; I

< ms.length; i++) { if(ms[i].getNo().equals(no)){ bo = true; break; } } } return bo; }}package com.youjiuye.bms;/* * 汽车租赁系统的功能模块类 * 1、管理员添加车库中的车辆信息 * 2、用户租赁车辆 * 3、用户查看车库中的车辆 * 4、用户查看自己租赁的车辆 * 5、管理员修改车辆的价格 * 6、用户结算租金 */public class CRMSService { // 1、管理员添加车库中的车辆信息 public boolean addVehicel(MotoVehicel mo){ boolean bo = false; MotoVehicel[] ms = MotoVehicel.getMs(); if(ms.length >

0) {for (int I = 0; I

< ms.length; i++) { if(ms[i] == null){ ms[i] = mo; bo = true; System.out.println("添加成功!"); break; } } } return bo; } // 2、用户租赁车辆 public void rent(Users u,MotoVehicel mo){ MotoVehicel[] ms = u.getUms(); for (int i = 0; i < ms.length; i++) { if(ms[i] == null){ ms[i] = mo; break; } } } // 4、用户查看自己租赁的车辆 public boolean browse(Users u){ boolean bo = false; MotoVehicel[] mo = u.getUms(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null){ System.out.println(mo[i].toString()); bo = true; } } } return bo; } // 5、管理员修改车辆的价格 public boolean update(String no,double price){ boolean bo = false; if(MotoVehicel.arrayExit()){ MotoVehicel[] ms = MotoVehicel.getMs(); for (int i = 0; i < ms.length; i++) { if(ms[i] != null && ms[i].getNo().equals(no)){ ms[i].setRentPrice(price); System.out.println("修改成功!"); System.out.println(ms[i]); bo = true; } } }else{ System.out.println("当前车库中还没有车辆"); } return bo; } // 6、用户结算租金 public double settleAccount(Users u,int days){ double price = 0; MotoVehicel[] mo = u.getUms(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null){ price += mo[i].getRentPrice() * days; } } } return price; } // 删除车库中的车辆 public void delete(MotoVehicel moo){ MotoVehicel[] mo = MotoVehicel.getMs(); if(mo.length >

0) {for (int I = 0; I

< mo.length; i++) { if(mo[i] != null && mo[i].equals(moo)){ mo[i] = null; } } } } // 根据车牌号来判断车库中是否含有该车辆 public boolean judgeExitMotoVehicel(String no){ boolean bo = false; MotoVehicel[] ms = MotoVehicel.getMs(); if(ms.length >

0) {for (int I = 0; I

< ms.length; i++) { if(ms[i].getNo().equals(no)){ bo = true; break; } } } return bo; }}package com.youjiuye.bms;public class Users { private String identity; private String password; // 存放租赁的车辆信息 private MotoVehicel[] ums = new MotoVehicel[10]; public MotoVehicel[] getUms() { return ums; } public void setUms(MotoVehicel[] ums) { this.ums = ums; } public Users(){} public Users(String identity, String password) { super(); this.identity = identity; this.password = password; } public String getIdentity() { return identity; } public void setIdentity(String identity) { this.identity = identity; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "Users [identity=" + identity + ", password=" + password + "]"; }}package com.youjiuye.bms;/* * 所有车的父类 * */public abstract class MotoVehicel { private String no; private String brand; private String Color; private int mileage; private double rentPrice; private static MotoVehicel[] ms= new MotoVehicel[10]; public MotoVehicel(){} public MotoVehicel(String no, String brand, String color, int mileage, double rentPrice) { super(); this.no = no; this.brand = brand; Color = color; this.mileage = mileage; this.rentPrice = rentPrice; } public String getNo() { return no; } public void setNo(String no) { this.no = no; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getColor() { return Color; } public void setColor(String color) { Color = color; } public int getMileage() { return mileage; } public void setMileage(int mileage) { this.mileage = mileage; } public double getRentPrice() { return rentPrice; } public void setRentPrice(double rentPrice) { this.rentPrice = rentPrice; } // 获取车库数组 public static MotoVehicel[] getMs() { return ms; } // 租赁功能 public abstract double rent(int days); // 初始化车库数组 public static final void init(){ Car c1 = new Car("001", "bwm","蓝色",10000, 500,"x5"); ms[0] = c1; Bus b1 = new Bus("8567", "景龙", "绿色",2000, 800,16); ms[1] = b1; } // 判断当前车库是否有车存在 public static boolean arrayExit(){ boolean bo = false; if(ms.length >

0) {for (int I = 0; I < ms.length; iTunes +) {if (Ms [I]! = null) {bo = true;} else {bo = false;} return bo } / / display the existing cars in the garage public static void show () {System.out.println ("current garage car:"); if (arrayExit ()) {for (int I = 0; I < ms.length) System.out.println +) {if (Ms [I]! = null) {System.out.println (Ms [I]);} else {System.out.println ("there is no vehicle in the current garage");} ```javapackage com.youjiuye.bms / * * bus * / public class Bus extends MotoVehicel {private int seatCount; public Bus () {} public Bus (String no, String brand, String color, int mileage, double rentPrice,int seatCount) {super (no, brand, color, mileage, rentPrice); this.seatCount = seatCount;} public int getSeatCount () {return seatCount;} public void setSeatCount (int seatCount) {this.seatCount = seatCount } @ Override public String toString () {return "Bus [license plate number:" + getNo () + "\ t Brand:" + getBrand () + "\ t seats:" + getSeatCount () + "\ t Color:" + getColor () + "\ t mileage:" + getMileage () + "\ t daily rent:" + getRentPrice () + "];} @ Override public double rent (int days) {return days * getRentPrice () }} package com.youjiuye.bms;/* * car * / public class Car extends MotoVehicel {private String type; public Car () {} public Car (String no, String brand, String color, int mileage, double rentPrice,String type) {super (no, brand, color, mileage, rentPrice); this.type = type;} public String getType () {return type } public void setType (String type) {this.type = type;} @ Override public String toString () {return "Car [license plate number:" + getNo () + "\ t Brand:" + getBrand () + "\ t Model:" + getType () + "\ t Color:" + getColor () + "\ t mileage:" + getMileage () + "\ t Daily Rent:" + getRentPrice () + "]" } @ Override public double rent (int days) {return days * getRentPrice ();}} these are all the contents of the article "how to implement a simple car rental system in java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report