亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請大神評價一下,還能優化嗎

請大神評價一下,還能優化嗎

woshishui1 2016-03-30 17:46:35
package com.imooc;import java.util.Scanner;public class Text { public static void main(String[] args) { // TODO Auto-generated method stub /*功能: 1、展示所有可租車輛 * ? ? ?2、選擇車型,租車量 * ? ? ?3、展示租車清單,包含:總金額、總載貨量及其車型、總載人量及其車型 *模型分析:1、數據模型分析 * ? ? ? ?2、業務模型分析 * 3、顯示和流程分析 */? ? ? ? Car[] carList={new Cathcar("東風標致",200,4),new Cathcar("沈陽卡龍",300,5),new Cathcar("重慶碉堡",400,10),? ? ? ?new Cathcar("廣東雪龍",550,12),new Camcar("迅達極致",650,16),new Camcar("粵運朗日",780,36),new Camcar("雪佛蘭",900,4),? ? ? ?new Camcar("豐田",980,5),new pika("皮卡",280,2,650)};? ? ? ?System.out.println("歡迎使用租車系統!");//歡迎用戶使用? ? ? ?System.out.println("請問是否需要租車?需要回復1,不需要回復0");//提示用戶選擇菜單? ? ? ?Scanner input=new Scanner(System.in);? ? ? ?int recieve=input.nextInt();? ? ? ?if(recieve==1){? ? ? System.out.println("你可租車的類型及其價目表:");? ? ? System.out.println("序號\t汽車名稱\t租金\t\t容量");? ? ? //for(int i=0;i<carList.length;i++){? ? int i=1;? ? for(Car currentCar:carList){? ? if(currentCar instanceof Camcar)? ? ? System.out.println(i+"\t"+currentCar.name+"\t"+currentCar.rent+"/天"+"\t\t"+currentCar.manNum+"人"); ?? ? else if(currentCar instanceof Cathcar)? ? ? System.out.println(i+"\t"+currentCar.name+"\t"+currentCar.rent+"/天"+"\t\t"+currentCar.thingsNum+"噸");? ? ? ? ? ? ? else? ? ? ? ? ? ? System.out.println(i+"\t"+currentCar.name+"\t"+currentCar.rent+"/天"+"\t\t"+currentCar.manNum+"人"+"\t"+currentCar.thingsNum+"噸");? ? ? ? i++;? ? ? ? ? ? ? ?}? ? System.out.println("請輸入您要租汽車的數量:");? ? int rentNum=input.nextInt();? ? int[] count=new int[carList.length];? ? for(int j=0;j<rentNum;j++){? ? System.out.println("請輸入您租車的序號:");? ? int rankCar=input.nextInt();? ? count[j]=rankCar;? ? rankCar=0;? ? }? ? System.out.println("請輸入租車的天數:");? ? int days=input.nextInt(); //顯示汽車賬單? ? double num=0;? ? for(int k=0;k<rentNum;k++){? ? ? num=num+carList[count[k]-1].rent*days;? ? ? System.out.println("汽車名稱:" +carList[count[k]-1].name );? ? }? ? System.out.println(carList[count[rentNum]].name +"\t\t" + "總金額:"+ num + "\t\t" +"租車時間:" + days);? ? }else? ? System.out.println("退出系統!");? ? ? ? ? ? ? ? }
查看完整描述

2 回答

?
慕村9732791

TA貢獻1條經驗 獲得超0個贊

我是新手,感覺你這個算法流程寫的很巧妙,很棒,我自己是想不出來的。不過你這里只有主方法,看不到其他類的代碼。貌似類中的屬性沒有私有化吧,看你沒有使用到get方法,另外計算總金額的功能是否可以做成父類中的一個方法呢


查看完整回答
反對 回復 2016-05-08
?
qq___524

TA貢獻171條經驗 獲得超74個贊

不需要優化了吧

查看完整回答
反對 回復 2016-04-19
  • 2 回答
  • 0 關注
  • 1462 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號