package?dadaCarRental;
import?java.util.Scanner;
public?class?DadaTest?{
????????
????public?static?void?main(String[]?args)?{
????????//Vehicle?→?Object(assignment)?→?Arrays
????????Vehicle?[]?vehicles?=?new?Vehicle[6];
????????vehicles?[0]?=?new?Vehicle("奧迪A4",4,0,500);
????????vehicles?[1]?=?new?Vehicle("馬自達6",4,0,400);
????????vehicles?[2]?=?new?Vehicle("皮卡雪6",4,2,450);
????????vehicles?[3]?=?new?Vehicle("金龍",20,0,800);
????????vehicles?[4]?=?new?Vehicle("松花江",0,4,400);
????????vehicles?[5]?=?new?Vehicle("依維柯",0,20,1000);
????????//test:System.out.println(vehicles[3].price);
????????
????????//welcome.
????????System.out.println("*****歡迎使用達達租車系統*****");
????????System.out.println("您是否要租車:1是?0?否");
????????
????????//Input?user's?choise.
????????Scanner?input?=?new?Scanner(System.in);
????????int?inputNum1?=?input.nextInt();
????????
????????//Judge?and?feedback?sth.
????????if(inputNum1?==?1){
????????????System.out.println("*****您可租車的類型及其價目表*****");
????????????System.out.println("序號"?+?"????"?+?"汽車名稱?"?+?"????????"?+?"租金"?+?"????"?+?"容量");
????????????for(int?i=0;?i<6;?i++){
????????????????System.out.print(i+1+"、???????"+vehicles[i].name?+?"????????"?+vehicles[i].price?+?"????");
????????????????vehicles[i].action(vehicles[i].passangersNum,?vehicles[i].cargoNum);
????????????????System.out.print("\n");
????????????}
????????????
????????????//Start?to?rent.
????????????System.out.println("請輸入您要租車的數量:");
????????????int?inputNum2?=?input.nextInt();
????????????int?totalPrice?=?0;
????????????int?totalP?=?0;
????????????int?totalC?=?0;
????????????int?pIndex?=?0;
????????????int?cIndex?=?0;
????????????
????????????//set?string?arrays?to?store?names.?
????????????String?[]?pVehicles?=?new?String[inputNum2];
????????????String?[]?cVehicles?=?new?String[inputNum2];
????????????
????????????????//Input?and?record?the?detils.
????????????????for(int?i=1;?i<=?inputNum2;?i++){
????????????????????System.out.println("請輸入第"?+?i?+?"輛車的序號");
????????????????????int?carIndex?=?input.nextInt();
????????????????????if(carIndex<=0?||?carIndex>=7){
????????????????????????System.out.println("你輸錯序號辣,重頭再來吧!╮(╯_╰)╭");
????????????????????????break;
????????????????????}
????????????????????
????????????????????totalPrice?=?totalPrice?+?vehicles[carIndex-1].price;
????????????????????
????????????????????if(vehicles[carIndex-1].passangersNum?!=0){
????????????????????????totalP?=?totalP?+?vehicles[carIndex-1].passangersNum;
????????????????????????pVehicles[pIndex]?=?vehicles[carIndex-1].name;
????????????????????????pIndex?=?pIndex?+?1?;
????????????????????}
????????????????????if(vehicles[carIndex-1].cargoNum?!=0){
????????????????????????totalC?=?totalC?+?vehicles[carIndex-1].cargoNum;
????????????????????????cVehicles[cIndex]?=?vehicles[carIndex-1].name;
????????????????????????cIndex?=?cIndex?+?1?;
????????????????????}
????????????????}
????????????
????????????//Print?the?bill?and?info.
????????????if(totalPrice?!=0?){
????????????????System.out.println("*****您的賬單*****");
????????????????System.out.println("總價:"+totalPrice+"元"+"\n");
????????????
????????????????System.out.print("可載人的車:");
????????????????if(totalP!=0){
????????????????????System.out.print("(可載"+totalP+"人)"+"\n");
????????????????????for(int?i?=?0;?i<pIndex;?i++?){
????????????????????????System.out.print(pVehicles[i]+"????");
????????????????????}
????????????????}else{
????????????????????System.out.println("根本沒有租辣!"+"\n");
????????????????}
????????????
????????????????System.out.print("\n"+"可載貨的車:");
????????????????if(totalC!=0){
????????????????????System.out.print("(可載"+totalC+"噸)"+"\n");
????????????????????????for(int?i?=?0;?i<cIndex;?i++){
????????????????????????????System.out.print(cVehicles[i]+"????");
????????????????????????}
????????????????}else{
????????????????????System.out.print("根本沒有租辣!");
????????????????????}
????????????????
????????????}else{
????????????????System.out.println("而且你要支付我咨詢費100塊!");
????????????????}
????????????
????????}else?if(inputNum1?==?0){
????????????System.out.println("好吧。。。白白!");
????????}else{
????????????System.out.println("按錯辣!╮( ̄⊿ ̄)╭!粗去重新來!");
????????}
????????
????????}????
????}
class?Vehicle?{
????String?name;
????int?passangersNum;
????int?cargoNum;
????int?price;
????
????//set?the?initial?paramater.
????Vehicle(String?vName,int?pNum,int?cNum,int?vPrice){
????????name?=?vName;
????????passangersNum?=?pNum;
????????cargoNum?=?cNum;
????????price?=?vPrice;
????};
????
????//judge?what?it?carrys.
????void?action(int?pnum,int?cnum){
????????if(pnum?!=?0){
????????????System.out.print("載客:"?+?pnum?+?"人");
????????}
????????if(cnum?!=?0){
????????????System.out.print("載貨"+?cnum?+?"噸");
????????}
????}
}
2016-06-22
第一次寫項目,自己分析自己的一些問題:
1、沒有再去劃分子類,直接用父類。
2、如果選車環節,隨便無序輸入序號的話,最后的車型輸出會很難看。打算后面用數組來解決。
3、沒有解決如果輸錯序號或量后怎么重新輸入的問題。
4、封裝、繼承、多態和接口都沒有使用,對此重要概念運用不熟練。寫的不像是面向對象而是面向過程的語言。
以上,還請大腿們多多賜教,蟹蟹。