java實現(xiàn)簡單汽車租賃系統(tǒng)
本文實例為大家分享了java實現(xiàn)汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、使用技術
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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
基于SpringBoot和Vue3的博客平臺的用戶注冊與登錄功能實現(xiàn)
本教程將指導您如何使用Spring?Boot和Vue3實現(xiàn)用戶注冊與登錄功能。我們將使用Spring?Boot作為后端框架,Vue3作為前端框架,同時使用MySQL作為數(shù)據(jù)庫,感興趣的朋友可以參考一下2023-04-04
Java實現(xiàn)動態(tài)數(shù)據(jù)源切換的實踐指南
在 Java 開發(fā)中,許多場景需要訪問多個數(shù)據(jù)庫,例如多租戶系統(tǒng)或讀寫分離架構(gòu),為了靈活高效地管理這些場景,動態(tài)數(shù)據(jù)源切換技術應運而生,所以本文給大家介紹了Java實現(xiàn)動態(tài)數(shù)據(jù)源切換的實踐指南,需要的朋友可以參考下2025-03-03
springboot對數(shù)據(jù)庫密碼加密的實現(xiàn)
這篇文章主要介紹了springboot對數(shù)據(jù)庫密碼加密的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-12-12
Mybatis-plus動態(tài)條件查詢QueryWrapper的使用案例
mybatis-plus框架功能很強大,把很多功能都集成了,下面這篇文章主要給大家介紹了關于Mybatis-plus動態(tài)條件查詢QueryWrapper的使用教程,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2022-07-07
Java中Easypoi實現(xiàn)excel多sheet表導入導出功能
這篇文章主要介紹了Java中Easypoi實現(xiàn)excel多sheet表導入導出功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-01-01

