答答租車系統規範程式碼示例
父類
package practice;
public class Car {
public String carname;
public int busload;//載客量
public double burden;//載貨量
public double money;//金額
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
載貨子類
package practice;
public class Busdencar extends Car {
public String carname;
public int busload;//載客量
public double burden;//載貨量
public double money;//金額
public Busdencar(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
載客子類
package practice;
public class Busloadcar extends Car {
public String carname;
public int busload;//載客量
public double burden;//載貨量
public double money;//金額
public Busloadcar(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
載客載貨子類
package practice;
public class PackUp extends Car {
public String carname;
public int busload;//載客量
public double burden;//載貨量
public double money;//金額
public PackUp(String carname,int busload, double burden,double money){
this.carname = carname;
this.busload = busload;
this.burden = burden;
this.money = money;
}
public String getCarname() {
return carname;
}
public void setCarname(String carname) {
this.carname = carname;
}
public int getBusload() {
return busload;
}
public void setBusload(int busload) {
this.busload = busload;
}
public double getBurden() {
return burden;
}
public void setBurden(double burden) {
this.burden = burden;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
使用者測試程式碼
package practice;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car[] car = {new Busloadcar("奧迪A4",4,0,500),new Busloadcar("馬自達6",4,0,400),
new PackUp("皮卡雪6",4,2,450),new Busloadcar("金龍",20,0,800),new Busdencar("松花江",0,4,400),
new Busdencar("依維柯",0,20,1000)};
//詢問使用者
System.out.println("歡迎使用答答租車系統:");
System.out.println("您是否要租車:1是 0否");
Scanner console = new Scanner(System.in);
int answer = console.nextInt();
int i = 1;
if(answer == 1){
//輸出可租車型及其價目表
System.out.println("您可租輸的型別及其價目表:");
System.out.println("序號" + " " + "汽車名稱" + " " + "租金" + " " + "容量");
for(Car foreachcar : car){
System.out.println(i + " " + foreachcar.getCarname() + " " + foreachcar.getMoney() + "元/天" + " "+ "載人:" +
foreachcar.getBusload() + "人" + " " + "載貨" + foreachcar.getBurden() + "噸");
i++;
}
//詢問使用者租車數量
System.out.println("請輸入您要租汽車的數量:");
int count = console.nextInt();
Car[] rentcar = new Car[count];
for(int j = 0 ; j
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1762/viewspace-2798499/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 答答租車系統,加入修改車價目的功能
- java第二季答答租車系統Java
- 答答租車(封裝+多型)封裝多型
- 答答租車系統(第一次寫)大家交流一下
- PHP 規範 - Symfony 程式碼規範PHP
- 達達租車系統
- 嗒嗒租車系統!!!!!
- 程式碼規範之前端編寫碼規範前端
- flutter如何統一程式碼規範Flutter
- Less程式碼規範
- css程式碼規範CSS
- 程式碼分支規範
- iOS程式碼規範iOS
- 程式碼規範整理
- JS程式碼規範JS
- CSS 程式碼格式規範CSS
- Git程式碼提交規範Git
- [C#] 程式碼規範C#
- 大廠程式碼規範
- 程式碼規範淺談
- Android 程式碼規範大全Android
- 統一規範化程式碼的命名風格
- HTML 程式碼註釋規範HTML
- JavaScript寫程式碼要規範JavaScript
- Java 程式碼規範if巢狀Java巢狀
- Airbnb JavaScript程式碼規範(完整)AIJavaScript
- 前端工程程式碼規範(四)——JS前端JS
- 前端工程程式碼規範(二)——HTML前端HTML
- Python程式碼規範性檢測Python
- Vue eslint 團隊程式碼規範VueEsLint
- HTML、CSS程式碼書寫規範HTMLCSS
- 談談BEM規範(含程式碼)
- 淺談專案程式碼規範
- 工人規範操作識別系統
- 簡化服裝ERP系統的規範流程和規範功用
- 花費 3 天時間整理的程式碼規範示例程式碼,你確定不進來看看嗎?
- 答答租車系統-感覺寫的好亂啊,還有很多異常都沒處理,等著我再寫個第二版
- C++實現管理系統的示例程式碼C++