這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)利用Java編寫一個(gè)簡單的租車系統(tǒng),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
實(shí)現(xiàn)目標(biāo)
java編寫一個(gè)控制臺版的“租車系統(tǒng)”
實(shí)現(xiàn)功能
1.展示所有可租車輛
2.選擇車型、租車量
3.展示租車清單,包含:總金額、總載貨量及其車型、總載人量及其車型
三大分析
數(shù)據(jù)模型分析
業(yè)務(wù)模型分析
顯示和流程分析
實(shí)現(xiàn)效果
租車頁面
租車賬單
實(shí)現(xiàn)思路
首先定義一個(gè)Car類,它包含基本功能:車名、載客數(shù)、載貨量、日租金。接著創(chuàng)建三個(gè)小類,分別是客車類、貨車類和皮卡類(既能載客又能載貨),它們都繼承Car類。最后需要一個(gè)主類,用于開啟整個(gè)系統(tǒng),調(diào)用每個(gè)小類。
實(shí)現(xiàn)代碼
package com.jinger; public abstract class Car { public int rent;//日租金 public int people;//載客人數(shù) public int loads;//載貨量 public String name;//車名 public int getRent(){ return rent; } public void setRent(int rent){ this.rent=rent; } public int getPeople(){ return people; } public void setPeople(int people){ this.people=people; } public int getLoads(){ return loads; } public void setLoads(int loads){ this.loads=loads; } public String getName(){ return name; } public void setName(String name){ this.name=name; } }