java實現(xiàn)簡單汽車租賃系統(tǒng)
本文實例為大家分享了java實現(xiàn)汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、使用技術(shù)
javaSE
二、實現(xiàn)功能
汽車租賃系統(tǒng)
具體要求如下:
使用面向?qū)ο蟮闹R實現(xiàn)一個汽車租賃系統(tǒng)
1.汽車租賃信息表如下

2.類和屬性

三、運行效果圖


1.先創(chuàng)建一個汽車類作為父類,這里有汽車的公共屬性:
public class Automobile {//汽車類
private String licensePlate;//車牌
private String brand;//品牌
private int rent;//租金
public Automobile() {
}
public Automobile(String licensePlate, String brand, int rent) {
this.licensePlate = licensePlate;
this.brand = brand;
this.rent = rent;
}
public String getLicensePlate() {
return licensePlate;
}
public void setLicensePlate(String licensePlate) {
this.licensePlate = licensePlate;
}
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;
}
}
2.創(chuàng)建一個轎車類,繼承汽車類的屬性
public class Car extends Automobile{//轎車
private String model;//型號
public Car(String model) {
this.model = model;
}
public Car(String licensePlate, String brand, int rent, String model) {
super(licensePlate, brand, rent);
this.model = model;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}
3.創(chuàng)建一個客車類,繼承汽車類的屬性
public class Passengercar extends Automobile{//客車
private String seatingCapacity;//座位數(shù)
public Passengercar(String seatingCapacity) {
this.seatingCapacity = seatingCapacity;
}
public Passengercar(String licensePlate, String brand, int rent, String seatingCapacity) {
super(licensePlate, brand, rent);
this.seatingCapacity = seatingCapacity;
}
public String getSeatingCapacity() {
return seatingCapacity;
}
public void setSeatingCapacity(String seatingCapacity) {
this.seatingCapacity = seatingCapacity;
}
}
4.創(chuàng)建測試類,用于實現(xiàn)這個系統(tǒng)
import java.util.Scanner;
public class TestAutomobile {
public static void main(String[] args) {
Car c1 = new Car("京NY28588", "寶馬X6", 800, "1");
Car c2 = new Car("京CNY3284", "寶馬550i", 600, "1");
Car c3 = new Car("京NT37465", "別克林蔭大道", 300, "1");
Car c4 = new Car("京NT969968", "別克GL8", 600, "1");
Passengercar p1 = new Passengercar("京6566754", "金杯,16座", 800, "2");
Passengercar p2 = new Passengercar("京8696997", "金龍,16座", 800, "2");
Passengercar p3 = new Passengercar("京9696996", "金杯,34座", 1500, "2");
Passengercar p4 = new Passengercar("京8696998", "金龍,34座", 1500, "2");
Scanner sc = new Scanner(System.in);
System.out.println("***********************歡迎光臨秋名山守望者汽車租賃公司***********************");
while (true){
System.out.println("1、轎車 2、客車");
System.out.println("請選擇你要租賃的汽車類型:");
String a=sc.next();
if (a.equals("1")){//轎車
System.out.println("請選擇你要租賃的汽車品牌:1、別克 2、寶馬");
String a1=sc.next();
if (a1.equals("2")){//寶馬
System.out.println("請選擇你要租賃的汽車類型:1、X6 2、550i");
String a2=sc.next();
if (a2.equals("2")){//550i
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+c2.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>7&&a3<=30){
System.out.println(c2.getRent()*a3*0.9+"元");
}else if(a3>30&&a3<=150){
System.out.println(c2.getRent()*a3*0.8+"元");
}else {
System.out.println(c2.getRent()*a3*0.7+"元");
}
}else {//x6
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+c1.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>7&&a3<=30){
System.out.println(c1.getRent()*a3*0.9+"元");
}else if(a3>30&&a3<=150){
System.out.println(c1.getRent()*a3*0.8+"元");
}else {
System.out.println(c1.getRent()*a3*0.7+"元");
}
}
}else {//別克
System.out.println("請選擇你要租賃的汽車類型:1、林蔭大道 2、GL8");
String a2=sc.next();
if (a2.equals("2")){//GL8
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+c4.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>7&&a3<=30){
System.out.println(c4.getRent()*a3*0.9+"元");
}else if(a3>30&&a3<=150){
System.out.println(c4.getRent()*a3*0.8+"元");
}else {
System.out.println(c4.getRent()*a3*0.7+"元");
}
}else {//別克林蔭大道
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+c3.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>7&&a3<=30){
System.out.println(c3.getRent()*a3*0.9+"元");
}else if(a3>30&&a3<=150){
System.out.println(c3.getRent()*a3*0.8+"元");
}else {
System.out.println(c3.getRent()*a3*0.7+"元");
}
}
}
/* Passengercar p1 = new Passengercar("京6566754", "金杯", 800, "2");
Passengercar p2 = new Passengercar("京8696997", "金龍", 800, "2");
Passengercar p3 = new Passengercar("京9696996", "金杯", 1500, "2");
Passengercar p4 = new Passengercar("京8696998", "金龍", 1500, "2");
*/
}else {//客車
System.out.println("請選擇你要租賃的汽車品牌:1、金龍 2、金杯");
String a1=sc.next();
if (a1.equals("1")){//金龍
System.out.println("請選擇你要租賃的汽車座位數(shù):1、16座 2、34座");
String a2=sc.next();
if (a2.equals("1")){//16座
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+p2.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>=3&&a3<7){
System.out.println(p2.getRent()*a3*0.9+"元");
}else if(a3>=7&&a3<30){
System.out.println(p2.getRent()*a3*0.8+"元");
}else if (a3>=30&&a3<150){
System.out.println(p2.getRent()*a3*0.7+"元");
}else {
System.out.println(p2.getRent()*a3*0.6+"元");
}
}else {//34
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+p4.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>=3&&a3<7){
System.out.println(p4.getRent()*a3*0.9+"元");
}else if(a3>=7&&a3<30){
System.out.println(p4.getRent()*a3*0.8+"元");
}else if (a3>=30&&a3<150){
System.out.println(p4.getRent()*a3*0.7+"元");
}else {
System.out.println(p4.getRent()*a3*0.6+"元");
}
}
}else {//金杯
System.out.println("請選擇你要租賃的汽車座位數(shù):1、16座 2、34座");
String a2=sc.next();
if (a2.equals("1")){//16座
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+p1.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>=3&&a3<7){
System.out.println(p1.getRent()*a3*0.9+"元");
}else if(a3>=7&&a3<30){
System.out.println(p1.getRent()*a3*0.8+"元");
}else if (a3>=30&&a3<150){
System.out.println(p1.getRent()*a3*0.7+"元");
}else {
System.out.println(p1.getRent()*a3*0.6+"元");
}
}else {//34
System.out.println("請選擇你要租賃的天數(shù)");
double a3=sc.nextInt();
System.out.println("分配給您的汽車牌號是:"+p3.getLicensePlate());
System.out.print("您需要支付的租賃費用是:");
if (a3>=3&&a3<7){
System.out.println(p3.getRent()*a3*0.9+"元");
}else if(a3>=7&&a3<30){
System.out.println(p3.getRent()*a3*0.8+"元");
}else if (a3>=30&&a3<150){
System.out.println(p3.getRent()*a3*0.7+"元");
}else {
System.out.println(p3.getRent()*a3*0.6+"元");
}
}
}
}
System.out.println();
System.out.println();
System.out.println("是否還要繼續(xù)選車 1繼續(xù) 2終止");
String x=sc.next();
if (x.equals("2")){
System.out.println("歡迎下次光臨!");
break;
}
System.out.println();
System.out.println();
}
}
}
1.轎車的實現(xiàn)

2.客車的實現(xiàn)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于springboot 中使用httpclient或RestTemplate做MultipartFile文件跨服務(wù)傳輸
這篇文章主要介紹了關(guān)于springboot 中使用httpclient或RestTemplate做MultipartFile文件跨服務(wù)傳輸?shù)膯栴},本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01
Java圖形界面之JFrame,JLabel,JButton詳解
這篇文章主要介紹了Java圖形界面之JFrame、JLabel、JButton詳解,文中有非常詳細的代碼示例,對正在學(xué)習(xí)java的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04
Spring?Cloud?中自定義外部化擴展機制原理及實戰(zhàn)記錄
這篇文章主要介紹了Spring?Cloud?中自定義外部化擴展機制原理及實戰(zhàn),本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02
部署springboot項目到云服務(wù)器的兩種方式(jar+war)
本文主要介紹了部署springboot項目到云服務(wù)器的兩種方式,主要介紹了jar和war兩種方式,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12
SpringBoot多環(huán)境開發(fā)該如何配置
這篇文章主要介紹了 SpringBoot多環(huán)境的開發(fā)配置詳情,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-09-09
Mybatis?Plus使用XML編寫動態(tài)sql的超簡易方法
這篇文章主要介紹了Mybatis?Plus使用XML編寫動態(tài)sql的超簡易方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-01-01
Java數(shù)據(jù)結(jié)構(gòu)之平衡二叉樹的原理與實現(xiàn)
平衡樹(Balance Tree,BT) 指的是,任意節(jié)點的子樹的高度差都小于等于1。常見的符合平衡樹的有,B樹(多路平衡搜索樹)、AVL樹(二叉平衡搜索樹)等。本文將詳細介紹平衡二叉樹的概念和實現(xiàn)原理以及它的實現(xiàn)2022-01-01
談?wù)凷pring Boot 數(shù)據(jù)源加載及其多數(shù)據(jù)源簡單實現(xiàn)(小結(jié))
這篇文章主要介紹了談?wù)凷pring Boot 數(shù)據(jù)源加載及其多數(shù)據(jù)源簡單實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04

