/**
* Create an interface to implement the leasing method
*
*/
Package Com.lxl.car;
Public interface Rent {
void rent (int day,int num);
}
/**
* Define an abstract Car class attribute: color, model, rental price
*
*/
Package Com.lxl.car;
Public abstract class Car implements rent{
Construction method
Public Car () {}
Private String size;//Model
Private String color;//Color
private int price;//Car rental price
/**
* @param size the size to set
*/
public void SetSize (String size) {
this.size = size;
}
/**
* @return The size
*/
Public String GetSize () {
return size;
}
/**
* @param color The color to set
*/
public void SetColor (String color) {
This.color = color;
}
/**
* @return The color
*/
Public String GetColor () {
return color;
}
/**
* @param price of the price to set
*/
public void Setprice (int. price) {
This.price = Price;
}
/**
* @return The price
*/
public int GetPrice () {
return price;
}
public void rent (int day,int num) {
System.out.println (Day*num*price);
}
}
/**
* Create a cargo car class, inherit the car class
*
*/
Package Com.lxl.car;
public class Freightcar extends Car {
}
/**
* Create a manned car class, inherit the car class
*
*/
Package Com.lxl.car;
public class Mannedcar extends car{
}
/**
* Create a manned cargo vehicle class, inherit the car class
*
*/
Package Com.lxl.car;
public class Bothcar extends car{
}
/**
* The main functions of this program are:
* Simulate a user car rental business process, the program starts, you need to show welcome page welcome users, and show the price of various models,
* and in the console to receive user input, let the user step by step to choose the type of car to rent, color, model, number of days rented, the number of rental,
* Finally shows the user's rental information (car type, color, model, number of days rented, number of leases, rental time),
* Calculate and show the cost of this lease.
*/
Package Com.lxl.car;
Import Java.util.Scanner;
public class Cartest {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Creating an input Stream object
SYSTEM.OUT.PRINTLN ("----------Welcome to the wife and children car rental system------------");
System.out.println ("The following are the models supported by our system and the detailed price of their rental");
Scanner sc = new Scanner (system.in);
Create manned car object Mcsmall for small
Mannedcar Mcsmall = new Mannedcar ();
Mcsmall.setsize ("1. Small:");
Mcsmall.setprice (300);
Create a cargo vehicle object Fcsmall for small
Freightcar fcsmall= new Freightcar ();
Fcsmall.setsize ("1. Small:");
Fcsmall.setprice (400);
Create dual-purpose car object Bcsmall for small
Bothcar bcsmall= new Bothcar ();
Bcsmall.setsize ("1. Small:");
Bcsmall.setprice (600);
Create a manned car object for medium
Mannedcar mcmiddle = new Mannedcar ();
Mcmiddle.setsize ("2. Medium:");
Mcmiddle.setprice (400);
Create a cargo vehicle object for medium
Freightcar fcmiddle = new Freightcar ();
Fcmiddle.setsize ("2. Medium:");
Fcmiddle.setprice (500);
Create a dual-purpose car object for medium
Bothcar bcmiddle= new Bothcar ();
Bcmiddle.setsize ("2. Medium:");
Bcmiddle.setprice (700);
Create manned vehicle objects for large
Mannedcar mcbig = new Mannedcar ();
Mcbig.setsize ("3. Large:");
Mcbig.setprice (500);
Create a cargo vehicle object for a large
Freightcar fcbig = new Freightcar ();
Fcbig.setsize ("3. Large:");
Fcbig.setprice (600);
Create dual-purpose car objects for large
Bothcar bcbig= new Bothcar ();
Bcbig.setsize ("3. Large:");
Bcbig.setprice (800);
Set color
Mcbig.setcolor ("1. Black");
Fcbig.setcolor ("2. Red");
Bcbig.setcolor ("3. Blue");
Output all car types and their prices
System.out.print ("1. Manned vehicle:" + "(" +mcsmall.getsize () +mcsmall.getprice () + "\ T");
System.out.print (Mcmiddle.getsize () +mcmiddle.getprice () + "\ T");
System.out.println (Mcbig.getsize () +mcbig.getprice () + ")");
System.out.print ("2. Laden car:" + "(" +fcsmall.getsize () +fcsmall.getprice () + "\ T");
System.out.print (Fcmiddle.getsize () +fcmiddle.getprice () + "\ T");
System.out.println (Fcbig.getsize () +fcbig.getprice () + ")");
System.out.print ("3. Dual-Use vehicle:" + "(" +bcsmall.getsize () +bcsmall.getprice () + "\ T");
System.out.print (Bcmiddle.getsize () +bcmiddle.getprice () + "\ T");
System.out.println (Bcbig.getsize () +bcbig.getprice () + ")");
SYSTEM.OUT.PRINTLN ("Car Color:" +mcbig.getcolor () + "\ T" +fcbig.getcolor () + "\ T" +bcbig.getcolor ());
Customer Selection Action
Boolean A = true;
int t = 0;
int s = 0;
while (a) {
A = false;
System.out.println ("Press 1, 2, 3 to select the type of car you are renting. ");
t = Sc.nextint ();
if (t = = 1) {
SYSTEM.OUT.PRINTLN ("You choose to be a manned car");
}else if (t = = 2) {
SYSTEM.OUT.PRINTLN ("You choose to be a laden car");
}else if (t = = 3) {
SYSTEM.OUT.PRINTLN ("You choose to be a dual-use car");
}else{
SYSTEM.OUT.PRINTLN ("You entered the wrong data, please re-enter:");
A = true;
}
}
A = true;
while (a) {
A = false;
System.out.println ("Press 1, 2, 3 to select the size of the car to be rented. ");
s = Sc.nextint ();
if (s = = 1) {
SYSTEM.OUT.PRINTLN ("You choose to be small");
}else if (s = = 2) {
SYSTEM.OUT.PRINTLN ("You choose to be Medium");
}else if (s = = 3) {
SYSTEM.OUT.PRINTLN ("You choose to be large");
}else{
SYSTEM.OUT.PRINTLN ("You entered the wrong data, please re-enter:");
A = true;
}
}
A = true;
while (a) {
A = false;
SYSTEM.OUT.PRINTLN ("Please press 1, 2, 3 to choose the color of the car rental. ");
int c = Sc.nextint ();
if (c = = 1) {
SYSTEM.OUT.PRINTLN ("You choose to be Black");
}else if (c = = 2) {
SYSTEM.OUT.PRINTLN ("You choose to be Red");
}else if (c = = 3) {
SYSTEM.OUT.PRINTLN ("You choose to be Blue");
}else{
SYSTEM.OUT.PRINTLN ("You entered the wrong data, please re-enter:");
A = true;
}
}
System.out.println ("Please enter the number of days you want to rent");
int day = Sc.nextint ();
System.out.println ("Please enter the quantity you want to rent");
int num = Sc.nextint ();
Select the output cost according to the customer
if (t ==1 && s ==1) {
System.out.print ("You have chosen a small manned car that will cost:");
Mcsmall.rent (Day,num);
}
if (t ==1 && s ==2) {
System.out.print ("You have chosen a medium-sized manned vehicle that will cost:");
Mcmiddle.rent (Day,num);
}
if (t ==1 && s ==3) {
System.out.print ("You have chosen a large manned vehicle that will cost:");
Mcbig.rent (Day,num);
}
if (t ==2 && s ==1) {
System.out.print ("You choose a small truck that will cost:");
Fcsmall.rent (Day,num);
}
if (t ==2 && s ==2) {
System.out.print ("You choose a medium-duty truck that will cost:");
Mcmiddle.rent (Day,num);
}
if (t ==2 && s ==3) {
System.out.print ("You choose a large-scale truck that will cost:");
Mcbig.rent (Day,num);
}
if (t ==3 && s ==1) {
System.out.print ("You are choosing a small dual-use car that will cost:");
Bcsmall.rent (Day,num);
}
if (t ==3 && s ==2) {
System.out.print ("You have chosen a medium-sized dual-purpose manned vehicle that will cost:");
Bcmiddle.rent (Day,num);
}
if (t ==3 && s ==3) {
System.out.print ("You have chosen a medium-sized dual-purpose manned vehicle that will cost:");
Bcbig.rent (Day,num);
}
}
}
Beginner: A simple car rental program (knock on the night) (Think Big God see, why I a simple program to knock so much, how can I improve?) )