java汽車租賃系統(tǒng)_第1頁
java汽車租賃系統(tǒng)_第2頁
java汽車租賃系統(tǒng)_第3頁
java汽車租賃系統(tǒng)_第4頁
java汽車租賃系統(tǒng)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、package RentCar;public class Bus extends MotoVehicleprivate int seatCount;/構造方法public Bus()public Bus(String no, String brand, int seatCount)super(no,brand);this.seatCount = seatCount;/獲取座位數(shù)public int getSeat()return seatCount;/計算租金public int calRent(int days)int rent = 0; if(seatCount = 16)rent = 8

2、00 * days;elserent = 1500 * days;return rent;package RentCar;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 void setType(String type)this.type = type;/返回轎車型號public Strin

3、g getType()return type;/實現(xiàn)父類抽象方法,計算租金public int calRent(int days)int rent = 0;if(寶馬.equals(getBrand()rent = days * 500;else if(豐田.equals(getBrand()if(type.equals(GL8)rent = days * 600;elserent = days * 300;return rent;package RentCar;public class Customer private String name;public Customer()public

4、Customer(String name) = name;public String getName()return name;public int calcTotalRent(MotoVehicle moto, int days)int rent = 0 ;for(int i = 0 ;i moto.length; i+)if(motoi!=null)rent = rent + motoi.calRent(days);return rent;package RentCar;public abstract class MotoVehicle private String no

5、; /車牌號private String brand; /品牌/構造方法public MotoVehicle()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);package RentCar;import java.util.

6、Scanner;public class Test public static void main(String args)Scanner input = new Scanner(System.in);int days = 0; /租賃的天數(shù)int motoType ; /汽車大類型String brand ; /汽車品牌String type = null; /汽車具體類型int seat; /座位數(shù)String no; /拍照String answer; /是否繼續(xù)MotoVehicle moto = new MotoVehicle10;Customer customer = new Cu

7、stomer(小明);System.out.println(歡迎來到汽車租賃公司!);System.out.print(請輸入要租賃的天數(shù):);days = input.nextInt();doSystem.out.print(請輸入要租賃的汽車類型(1.轎車 2.客車):);motoType = input.nextInt();int random = (int)(Math.random()*(99999-10000)+10000);switch(motoType)case 1:no = 粵A + random; /車輛牌照System.out.print(請輸入要租賃的汽車品牌(1.寶馬

8、2.豐田):);if(input.nextInt() = 1)brand = 寶馬;type = 320i;elsebrand = 豐田;type = RAV4;/實例化一個轎車對象,并添加到moto數(shù)組中for(int i = 0 ; i moto.length ;i +)if(motoi = null)motoi = new Car(no,brand,type);break;break;case 2:no = 粵A + random; System.out.print(請輸入要租賃的汽車品牌(1.黃海 2.金龍):);/根據(jù)選擇得到汽車品牌if(input.nextInt() =1)bra

9、nd = 黃海;elsebrand = 金龍;System.out.print(請輸入客車的座位數(shù):);seat = input.nextInt(); /汽車座位數(shù)/實例化一個轎車對象,并添加到moto數(shù)組中for(int i = 0 ; i moto.length ;i +)if(motoi = null)motoi = new Bus(no,brand,seat); /實例化一個汽車對象break;break;System.out.print(是否繼續(xù)租車?(y/n):);answer = input.next();while(answer.equals(y);System.out.pri

10、ntln(汽車牌號t汽車品牌);for(int i = 0 ; i moto.length ;i +)if(motoi != null)if(motoi instanceof Car)Car c = (Car)motoi;System.out.println(c.getNo()+t+c.getBrand();elseBus b = (Bus)motoi;System.out.println(b.getNo()+t+b.getBrand();System.out.println(客戶名:+customer.getName()+,租賃天數(shù):+days+,總費用:+customer.calcTotalRent(moto, days);package RentCar;public class Truck extends MotoVehicle private int weight; /噸位public Truck()public Truck(String no, String brand

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論