Java實(shí)現(xiàn)簡(jiǎn)單汽車租賃系統(tǒng)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)簡(jiǎn)單汽車租賃系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
需求如下:

問題分析:
首先應(yīng)當(dāng)構(gòu)建一個(gè)MotoVehicle的抽象(abstract)類,類里面包含一個(gè)brand屬性,表示汽車品牌;還包含一個(gè)no屬性,表示汽車牌號(hào);
package cn.jbit.car;
public abstract class MotoVehicle {
private String no;
private String brand;
/**
* 無(wú)參構(gòu)造方法
*/
public MotoVehicle() {
}
/**
* 有參構(gòu)造方法
* @param no 汽車牌號(hào)
* @param brand 汽車品牌
*/
public MotoVehicle(String no,String brand) {
this.no=no;
this.brand=brand;
}
public String getNo() {
return no;
}
public String getBrand() {
return brand;
}
public abstract int calRent(int days);
}其次,應(yīng)有Car類繼承自MotoVehicle類,并有一個(gè)type屬性,表示轎車型號(hào),應(yīng)有一個(gè)計(jì)算租金的方法calRent()
package cn.jbit.car;
public class Car extends MotoVehicle{
private String type;
public Car() {
}
public Car (String no,String brand,String type) {
super(no,brand);
this.type=type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public int calRent(int days) {
// TODO Auto-generated method stub
if("2".equals(type)) {
return days*500;
}
else if ("1".equals(type)) {
return days*600;
}
else {
return 300*days;
}
}
}再次,應(yīng)有Bus類繼承自MotoVehicle類,并有一個(gè)CountSet屬性,表示客車的容量,同樣的,應(yīng)有一個(gè)計(jì)算租金的方法calRent();
package cn.jbit.car;
public class Bus extends MotoVehicle {
int CountSet;
public Bus() {
}
/**
* 帶參構(gòu)造函數(shù)
*/
public Bus(String brand,String no,int CountSet) {
super(brand,no);
this.CountSet=CountSet;
}
public int getCountSet() {
return CountSet;
}
public void setCountSet(int countSet) {
CountSet = countSet;
}
@Override
public int calRent(int days) {
// TODO Auto-generated method stub
if(CountSet<16) {
return 800*days;
}
else {
return 1600*days;
}
}
}最后,以上三類應(yīng)在test類中測(cè)試;
package cn.jbit.car;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String no,brand,mtype;
int countSet,days;
Scanner input=new Scanner(System.in);
System.out.println("*****歡迎來到汽車租賃公司!******");
System.out.println("請(qǐng)輸入天數(shù):");
days=input.nextInt();
System.out.println("請(qǐng)輸入車輛類型:");
System.out.println("1、轎車 2、客車");
mtype=input.next();
if("1".equals(mtype)) {
System.out.println("請(qǐng)輸入轎車品牌:");
System.out.println("1、寶馬 2、別克");
brand=input.next();
if("1".equals(brand)) {
System.out.println("2、寶馬550i:500");
System.out.println("請(qǐng)輸入轎車型號(hào):");
mtype=input.next();
System.out.println("請(qǐng)輸入輛數(shù):");
int count=input.nextInt();
Car car=new Car("遼B000",brand,mtype);
System.out.println("您需支付:"+count*car.calRent(days));
}
else {
System.out.println("1、別克商務(wù)GL8:600 3、別克林蔭大道:300");
mtype=input.next();
System.out.println("請(qǐng)輸入輛數(shù):");
int count=input.nextInt();
Car car=new Car("遼B000",brand,mtype);
System.out.println("您需支付:"+count*car.calRent(days));
}
}
else {
System.out.println("請(qǐng)輸入品牌:");
System.out.println("1、金杯 2、金龍");
brand=input.next();
System.out.println("請(qǐng)輸入座位數(shù):");
countSet=input.nextInt();
System.out.println("請(qǐng)輸入輛數(shù):");
int count=input.nextInt();
Bus b=new Bus(brand,"遼B000",countSet);
System.out.println("您需支付:"+b.calRent(days)*count);
}
}
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
springboot實(shí)現(xiàn)啟動(dòng)直接訪問項(xiàng)目地址
這篇文章主要介紹了springboot實(shí)現(xiàn)啟動(dòng)直接訪問項(xiàng)目地址,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
MyBatis中使用分頁(yè)插件PageHelper實(shí)現(xiàn)分頁(yè)功能
分頁(yè)是經(jīng)常使用的功能,本文主要介紹了Mybatis中處理特殊SQL處理邏輯,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06
MyBatis?Plus如何實(shí)現(xiàn)獲取自動(dòng)生成主鍵值
這篇文章主要介紹了MyBatis?Plus如何實(shí)現(xiàn)獲取自動(dòng)生成主鍵值問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
spring?boot?mybatis日志輸出到控制臺(tái)的方法實(shí)踐
在開發(fā)過程中我們往往需要打印出SQL語(yǔ)句,這樣就方便我們監(jiān)控問題,本文主要介紹了spring?boot?mybatis日志輸出到控制臺(tái)的方法實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
Mybatis 動(dòng)態(tài)sql的編寫與開啟二級(jí)緩存
二級(jí)緩存是Mapper級(jí)別的緩存,多個(gè)SqlSession去操作同一個(gè)Mapper中的SQL語(yǔ)句,則這些SqlSession可以共享二級(jí)緩存,即二級(jí)緩存是跨SqlSession的,這篇文章主要介紹了Mybatis 動(dòng)態(tài)sql的編寫|開啟二級(jí)緩存,需要的朋友可以參考下2023-02-02

