java car rental system code

Sketch

The first year of college.
java car rental system code
Operation result:

Console:

The above is the overall implementation effect.

Analysis

I store the car as an array:

public class Car {

    String[ ] name = new String[50]; 
    int[ ] state = new int[50]; 
    String[ ] date=new String[50]; 
    int[] count=new int[50]; 
    Scanner in=new Scanner(System.in); 
    int xuhao; 
    int k=3; 
    boolean flag=true; 
    public Car(){
        ...
    }

Set the number in the original system first:

// Initializer 
    //Array initialization
    public void Car(){ 
        this.name[0]="BMW 5 i"; 
        this.state[0]=0;  
        this.date[0]="2017-03-01"; 

        this.name[1]="Benz business"; 
        this.state[1]=1;

        this.name[2]="Public Qolf"; 
        this.state[2]=1; 

        this.name[3]="Cherie 5"; 
        this.state[3]=0; 
        this.date[3]="2017-03-06"; 

Then, in the method, switch is used to facilitate the operation of the system.

//menu
    void caidan(){ 

        System.out.println("Welcome to taxi management system");
        System.out.println("----------------------------");
        System.out.println("1.Newly added CAR");
        System.out.println("2.See CAR");
        System.out.println("3.delete CAR");
        System.out.println("4.Lend CAR");
        System.out.println("5.return CAR");
        System.out.println("6.retreat        Out");
        System.out.println("----------------------------");
        System.out.println("Please select:");


        //Choice
        xuhao=in.nextInt(); 
        switch(xuhao){ 
        case 1:
            this.zengjia();
            break; 
        case 2:
            this.chakan();
            break; 
        case 3:
            this.shanchu();
            break; 
        case 4:
            this.jiechu();
            break; 
        case 5:
            this.guihuan();
            break; 
        case 6:
            this.tuichu();
            break; 
        default:System.out.print("Sorry, your input is wrong! Please enter 1-6:"); 
        }
    }

In this way, the program interface is more intuitive and the code is more concise.

This code will pop up every time a value is entered (called) when the program is running. Press0Return, or press any key to re-enter.


//Return
    void fanhui(){
        System.out.print("Press any number to re-enter; press 0 to return:"); 
        xuhao=in.nextInt(); 
        if(xuhao==0){ 
            System.out.println("-------------------------------------"); 
            this.caidan(); 
        } 
        else{
            this.zengjia();
        } 
    }

One of the actions – > Return

//return
    void guihuan(){
        System.out.println("return");
        System.out.println("********Welcome to return CAR page******************");
        System.out.println("Please enter also CAR Name of:");
        Scanner input = new Scanner(System.in);
        double  price = 0.0;
        String name = input.next();
        for(int i = 0;i<this.name.length;i++){

            if(this.name[i]!=null){ //Yes

                if(this.name[i].equalsIgnoreCase(name) && this.state[i] == 0){ //You can return it on loan
                    this.state[i] = 1;
                    System.out.println("Please enter the return time(year-month-day):");
                    Scanner inputDate = new Scanner(System.in);
                    //Acquisition time difference
                    long charge = charge1(this.date[i],inputDate.next());
                    price = charge * 1;
                    System.out.println(this.name[i]+"Return succeeded");
                    System.out.println("You should"+price+"element");
                    //Clearance Time 
                    this.date[i] = null;
                    break;

                }

            }else{
                System.out.println("No matching information found");
                break;
            }
        }

...

//Test class
    public static void main(String[] args) {

        Car c=new Car();
        c.Car();
        c.caidan();
    }

The relevant Car code has been posted on github.

https://github.com/Liumce/Car.git

If you have any questions, please give me more advice!

Keywords: github Java git

Added by adrianl on Thu, 30 Apr 2020 22:58:10 +0300