Car rental System

Source: Internet
Author: User

Parent class

Public abstract class Superclass {
Public double money;//Unit price
Private double moneys;//Total Price
private int sky;//Days
Public String info;//models and license plates
Private String discount;//Discount

/*
* Get and set days
*/
public int Getsky () {
return sky;
}

public void Setsky (double sky) {
if (Sky > 0) {
This.sky = (int) sky;
if (Sky!=this.sky) {
this.sky++;
}

} else {
SYSTEM.OUT.PRINTLN ("input error");
}

}

/*
* Get and Set unit price
*/
Public double Getmoney () {
return money;
}

public void Setmoney (double money) {
This.money = money;
}

/*
* Get and set Total price
*/
Public double Getmoneys () {
return moneys;
}

public void Setmoneys (double moneys) {
This.moneys = Moneys;
}

/*
* Get and set discounts
*/
Public String Getdiscount () {
return discount;
}

public void SetDiscount (String discount) {
This.discount = discount;
}

/*
* Select model
*/
Public String getInfo (int i) {
return null;
}
/*
* Daily rental price
*/
public double Getmoney (int i) {
return i;

}
/*
* Total car price (sky) means the number of days
*/
public abstract void Summoneys ();
/*
* Show the number of days to borrow and how many folds to play
*/
public abstract void Showdiscount ();
/*
* Display rental and vehicle models to customers
*/
public abstract void Showcar ();
/*
* Output Information
*/
public abstract void Showinfo ();
}

Car Inheritance Parent class

public class Cardemo extends superclass{


/*
* Select model
*/
Public String getInfo (int i) {//Information
String[] Limousine = {"BMW X6", "BMW 550i", "Buick Boulevard", "Buick GL8"};//models
String[] Tag = {"Jing NY28588", "Jing CNY3284", "Jing NT37465", "Jing NT96968"};//license
return info = "The model you selected is:" + limousine[i] + "license plate number is:" + tag[i];
}

/*
* Daily rental price
*/
public double Getmoney (int i) {
Double[] Money = {800, 600, 300, 600};
return This.money = Money[i];
}

/*
* Total car price (sky) means the number of days
*/
public void Summoneys () {
if (Getsky () > 0 && Getsky () < 7) {
This.setmoneys (This.getmoney () * Getsky ());
} else if (Getsky () >= 7 && Getsky () < 30) {
This.setmoneys ((This.getmoney () * 0.9) * Getsky ());
} else if (Getsky () >= && Getsky () < 150) {
This.setmoneys ((This.getmoney () * 0.8) * Getsky ());
} else if (Getsky () >= 150) {
This.setmoneys ((This.getmoney () * 0.7) * Getsky ());
}
}

/*
* Show the number of days to borrow and how many folds to play
*/
public void Showdiscount () {
Summoneys ();
if (Getsky () > 0 && Getsky () < 7) {
SetDiscount (Getsky () + "Day less than 7 days according to the original price processing");
} else if (Getsky () >= 7 && Getsky () < 30) {
SetDiscount (Getsky () + "days greater than or equal to seven days less than 30 days playing 90 percent");
} else if (Getsky () >= && Getsky () < 150) {
SetDiscount (Getsky () + "days greater than or equal to 30 days less than 150 days playing 80 percent");
} else if (Getsky () >= 150) {
SetDiscount (Getsky () + "days greater than or equal to 150 days dozen 70 percent");
}

}
public void Showcar () {
System.out.println (info+ "\ t a day's price is:" +getmoney ());

}

/*
* Output Information
*/
public void Showinfo () {
SYSTEM.OUT.PRINTLN (info + "T-day Price:" + Getmoney () + "yuan \ T" + this.getdiscount ()
+ "\ t payable:" + This.getmoneys ());
}
}

Instantiation of the Automobile class

public class Output {
public void NewObject () {
Scanner input = new Scanner (system.in);
Superclass car = new Cardemo ();
SYSTEM.OUT.PRINTLN ("Choose Sedan Success");
System.out.println ("1. BMW X6\t2 BMW 550i\t3. Buick Boulevard \t4. Buick GL8");
try {
int select = Input.nextint ()-1;
Car.getinfo (select);
Car.getmoney (select);
Car.showcar ();
System.out.println ("Please enter the number of days:");
Double sc = input.nextdouble ();
if (sc > 0) {
Car.setsky (SC);
Car.getsky ();
Car.showdiscount ();
Car.showinfo ();
} else {
SYSTEM.OUT.PRINTLN ("input error");
}
} catch (Exception e) {

E.printstacktrace ();
SYSTEM.ERR.PRINTLN ("Please re-enter");
New Output (). NewObject ();
}

}

}

Bus class inherit automobile class

public class CarDemo1 extends cardemo{

Public String getInfo (int i) {//Information
String[] Limousine = {"Golden cup 16 seats", "Jinbei 34", "Golden Dragon 16", "Jinlong 34"};//models
String[] Tag = {"Jing 6566754", "Jing 8696998", "Jing 8696997", "Jing 9696996"};//license
return info = "The model you selected is:" + limousine[i] + "license plate number is:" + tag[i];
}
public double Getmoney (int i) {//Unit price
Double[] Money = {800, 1500, 800,1500};
return super.money=money[i];
}
public void Summoneys () {
if (Getsky () > 0 && Getsky () < 3) {
This.setmoneys (This.getmoney () * Getsky ());
} else if (Getsky () >= 3 && Getsky () < 7) {
This.setmoneys ((This.getmoney () * 0.9) * Getsky ());
} else if (Getsky () >=7 && Getsky () < 30) {
This.setmoneys ((This.getmoney () * 0.8) * Getsky ());
} else if (Getsky () >= 30&&getsky () < 150) {
This.setmoneys ((This.getmoney () * 0.7) * Getsky ());
}else if (Getsky () >=150) {
This.setmoneys ((This.getmoney () * 0.6) * Getsky ());
}
}
public void Showdiscount () {
Summoneys ();
if (Getsky () > 0 && Getsky () < 3) {
SetDiscount (Getsky () + "Day less than 3 days according to the original price processing");
} else if (Getsky () >= 3 && Getsky () < 7) {
SetDiscount (Getsky () + "days greater than or equal to 3 days less than 7 days playing 90 percent");
} else if (Getsky () >=7 && Getsky () < 30) {
SetDiscount (Getsky () + "days greater than or equal to 7 days less than 30 days playing 80 percent");
} else if (Getsky () >= 30&&getsky () < 150) {
SetDiscount (Getsky () + "days greater than or equal to 30 days less than 150 days playing 70 percent");
}else if (Getsky () >=150) {
SetDiscount (Getsky () + "days greater than or equal to 150 days dozen 60 percent");
}
}
}

Example of Bus class

public class Test_coach {
public void Show_coach () {
Scanner input = new Scanner (system.in);
CarDemo1 car1 = new CarDemo1 ();
SYSTEM.OUT.PRINTLN ("Choose bus Success");
System.out.println ("1. Gold Cup 16 seats \t2. Jinbei 34 seats \t3. jinlong 16 seats \t4. Jinlong 34");
try {
int select = Input.nextint ()-1;
Car1.getinfo (select);
Car1.getmoney (select);
Car1.showcar ();
System.out.println ("Please enter the number of days:");
Double sc = input.nextdouble ();
if (sc > 0) {
Car1.setsky (SC);
Car1.showdiscount ();
Car1.showinfo ();
}else{
SYSTEM.OUT.PRINTLN ("input error");
}
} catch (Exception e) {
E.printstacktrace ();
SYSTEM.ERR.PRINTLN ("Please re-enter");
New Test_coach (). Show_coach ();
}


}
}

Test class

public class Test_car {
public static void Main (string[] args) {
Scanner input=new Scanner (system.in);
System.out.println ("Welcome to the car rental system!") ");
System.out.println ("1. Sedan \t2. Passenger Car");

Boolean panduan=true;
while (Panduan==true) {
String Judge=input.next ();
Switch (judge) {
Car
Case "1":
Panduan=false;
New Output (). NewObject ();
Break

Case "2":
Bus
Panduan=false;
New Test_coach (). Show_coach ();
Break
Default
SYSTEM.OUT.PRINTLN ("Input error, please re-enter");
}
}

System.out.println ("Thanks for use");
}
}

Car rental System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.