答答租車系統規範程式碼示例
父類
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
- Panorama系統程式開發規範
- Android 程式碼規範 - 命名規範Android
- Android程式碼規範:命名規範Android
- 程式碼規範之前端編寫碼規範前端
- 達達租車系統
- flutter如何統一程式碼規範Flutter
- 程式碼分支規範
- 程式碼規範整理
- JS程式碼規範JS
- 前端程式碼規範前端
- iOS程式碼規範iOS
- Less程式碼規範
- css程式碼規範CSS
- iOS 程式碼規範iOS
- 程式碼部署規範
- 嗒嗒租車系統!!!!!
- 程式碼規範淺談
- CSS 程式碼格式規範CSS
- Git程式碼提交規範Git
- 程式碼書寫規範
- Python 程式碼規範Python
- Python程式碼規範Python
- 大廠程式碼規範
- [C#] 程式碼規範C#
- 統一規範化程式碼的命名風格
- Airbnb JavaScript程式碼規範(完整)AIJavaScript
- HTML 程式碼註釋規範HTML
- JavaScript寫程式碼要規範JavaScript
- Android 程式碼規範大全Android
- Java程式碼註釋規範Java
- Java 程式碼規範if巢狀Java巢狀
- 編碼規範系列:css規範CSS
- 工人規範操作識別系統