有一些冗餘程式碼, 只是實現了功能
package com.dada;
public class Cars {
//定義子類應該有的屬性
public String carName; //車名
public int id, carryMan; //編號, 載客量
public float unitPrice, carryGoods; //每日價格, 載貨量
}
package com.dada;
public class Bus extends Cars{
//建立有參構造方法
public Bus(int id, String carName, float unitPrice, int carryMan ) {
this.carName = carName;
this.id = id;
this.carryMan = carryMan;
this.unitPrice = unitPrice;
}
}
package com.dada;
public class Truck extends Cars {
public Truck( int id, String carName, float unitPrice, float carryGoods ){
this.carName = carName;
this.id = id;
this.unitPrice = unitPrice;
this.carryGoods = carryGoods;
}
}
package com.dada;
public class PickUp extends Cars {
public PickUp( int id, String carName, float unitPrice, int carryMan, float carryGoods ){
this.carName = carName;
this.id = id;
this.carryMan = carryMan;
this.unitPrice = unitPrice;
this.carryGoods = carryGoods;
}
}
package com.dada;
import java.util.Scanner;
public class Users {
static Cars[] cars;
static int[] carsId;
static int days;
static float allMoney;
static int allPersons;
static float allGoods;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("歡迎進入噠噠租車系統:n 是否要租車:1 是 0 否");
Scanner input = new Scanner(System.in);
int entry = input.nextInt();
if(entry == 1) {
//羅列車目型別
Users use = new Users();
System.out.println("您可租車的型別及價目表:n 編號t 車名t 單價tt 容量");
use.getCars();
System.out.println("請選擇要租車的數量:");
int numbers = input.nextInt();
//呼叫租車數量
use.carsNum(numbers);
System.out.println("輸入要租的天數: ");
days = input.nextInt();
//呼叫列印結果
use.display();
}
}
//車目型別
public void getCars(){
Bus audi = new Bus(1, "奧迪a4", 500f, 5);
Bus mzd = new Bus(2, "馬自達6", 400f, 5);
Truck shj = new Truck(3, "松花江", 400f, 4);
Truck ywk = new Truck(4, "依維柯", 1000f, 20);
PickUp mq = new PickUp(5, "猛禽", 1200f, 5, 5);
PickUp cc = new PickUp(6, "長城", 600f, 5, 3);
Cars cars[] = {audi, mzd, shj, ywk, mq, cc};
for(Cars car:cars){
if(car.getClass() == Bus.class) {
System.out.println(car.id + "t" + car.carName + "t" + car.unitPrice + "/天tt" + car.carryMan + "人");
} else if(car.getClass() == Truck.class) {
System.out.println(car.id + "t" + car.carName + "t" + car.unitPrice + "/天tt" + car.carryGoods + "噸");
} else if(car.getClass() == PickUp.class) {
System.out.println(car.id + "t" + car.carName + "t" + car.unitPrice + "/天tt" + car.carryMan + "人," + car.carryGoods + "噸");
}
}
}
//租車數量
void carsNum(int numbers) {
//選擇每輛車的編號組成的陣列
Scanner input = new Scanner(System.in);
//定義陣列長度
carsId = new int[numbers];
for(int i = 1; i
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1600/viewspace-2798914/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 程式碼質量第 5 層 - 只是實現了功能
- CRC冗餘校驗碼的介紹和實現
- 優化C++程式碼(4):消除冗餘程式碼優化C++
- 找出冗餘索引的指令碼索引指令碼
- VS Code 正則匹配(冗餘程式碼批量清理方法)
- 去除冗餘 – 精簡您的CSS樣式程式碼CSS
- 網路冗餘技術
- iOS專案冗餘資源掃描指令碼iOS指令碼
- 小白讀iOS冗餘資源掃描指令碼iOS指令碼
- 一個利用正規表示式進行程式碼重構,去除冗餘程式碼的例子行程
- 冗餘程式碼都走開——前端模組打包利器 Rollup.js 入門前端JS
- find 命令刪除冗餘 Nginx 錯誤日誌並實現備份Nginx
- 修改ASM磁碟組冗餘模式ASM模式
- 廉價冗餘磁碟陣列陣列
- JavaScript 實現sprintf 功能程式碼JavaScript
- vue專案實現記住密碼到cookie功能(附原始碼)!這只是demoVue密碼Cookie原始碼
- 細說 Azure Storage 的冗餘策略
- MySQL 冗餘和重複索引薦MySql索引
- 細說TF服務鏈丨服務鏈的冗餘是如何實現的
- 海明碼舉例分析(監督關係與資訊碼 冗餘位)
- 碼教授教你一些系統功能實現的操作
- Java-Annotation的一種用法(消除程式碼中冗餘的if/else或switch語句)Java
- 資料庫設計——冗餘欄位資料庫
- 如何消除冗餘資料的安全風險?
- FHRP - 閘道器冗餘協議協議
- 虛擬路由冗餘協議VRRP路由協議VR
- ASM可以更改冗餘度&增加failgroup嗎?ASMAI
- MSSQL冗餘欄位的策略和管理SQL
- 冗餘是什麼意思?與雙機熱備有什麼區別?
- 實現【檢視更多】功能的程式碼
- 10行程式碼實現微信小程式支付功能,使用小程式雲開發實現小程式支付功能(行程微信小程式
- 資料庫設計之欄位冗餘資料庫
- FTP客戶端c程式碼功能實現FTP客戶端C程式
- WPF DataGrid分頁功能實現程式碼
- 驚了!7 行程式碼優雅地實現 Excel 檔案生成&下載功能行程Excel
- 幾道JS程式碼手寫題以及一些程式碼實現JS
- 現在,UICollectionViews有了簡單的重排功能UIView
- 不只是寫程式碼