第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

分享一下代碼求大佬給一點(diǎn)優(yōu)化思路

import?java.util.Scanner;
import?java.lang.System;
//車的抽象類
public?abstract?class?car?{

??String?carName;//車名
??int?persons;//載客量
??double?weights;//載貨量
??int?rent;//租金
????
??//給客車使用的構(gòu)造方法
??public?car(String?carName,int?persons,int?rent)?{
????super();
????this.carName=carName;
????this.persons=persons;
????this.rent=rent;
??}
????
??//給貨車使用的構(gòu)造方法
??public?car(String?carName,double?weights,int?rent)?{
????super();
????this.carName=carName;
????this.weights=weights;
????this.rent=rent;
??}
????
??//給皮卡使用的構(gòu)造方法
??public?car(String?carName,double?weights,int?persons,int?rent)?{
????super();
????this.carName=carName;
????this.weights=weights;
????this.persons=persons;
????????this.rent=rent;
??}
????
????abstract?void?show();
}

//客車類
public?class?passengerCar?extends?car?{
??public?passengerCar(String?carName,int?persons,int?rent)?{
????super(carName,persons,rent);
??}
????
??//重寫父類show方法。
????public?void?show(){
????????System.out.println(carName+"??"+rent+"元/天??載人:"+persons+"人");
????}
}

//貨車類
public?class?TruckCar?extends?car?{
????public?TruckCar?(String?carName,double?weights,int?rent){
????????super(carName,weights,rent);
????}
????
????public?void?show(){
????????System.out.println(carName+"??"+rent+"元/天??載貨:"+weights+"噸");
????}
}

//皮卡類
public?class?pickupCar?extends?car?{
????public?pickupCar?(String?carName,double?weights,int?persons,int?rent){
????????super(carName,weights,persons,rent);
????}
????
????public?void?show(){
????????System.out.println(carName+"??"+rent+"元/天??載人:"+persons+"人,載貨:"+weights+"噸");
????}
}

//租車前臺(tái)系統(tǒng)類
public?class?carRentSystem?{

????public?static?void?main(String[]?args)?{
????car[]?cars={new?TruckCar?("松花江",4.0,?400),new?TruckCar?("依維柯",20.0,1000),new?pickupCar?("皮卡雪",?4.0,?2,?450),new?passengerCar?("馬自達(dá)",?4,?400),new?passengerCar?("奧迪A4",?4,?500)};
????System.out.println("歡迎使用嗒嗒租車系統(tǒng):");
????System.out.println("您是否要租車:1是?0否");
????Scanner?s1=new?Scanner(System.in);
????int?xz=s1.nextInt();//捕捉用戶選擇
????if?(xz==1)?{
????????System.out.println("您可租車的類型及其價(jià)目表:");
????????System.out.println("序號(hào)???汽車名字???租金???容量");
????????for?(int?i?=?0;?i?<?cars.length;?i++)?{
????????????System.out.print(i+"???");
????????????cars[i].show();
????????}
????????System.out.println("請(qǐng)輸入您要租汽車的數(shù)量:");
????????int?sl=s1.nextInt();//捕捉用戶輸入的數(shù)量
????????int[]?sum=new?int[sl];//用來存儲(chǔ)用戶輸入的車的序號(hào)。
????????for?(int?i?=?0;?i?<?sl;?i++)?{
????????????System.out.printf("請(qǐng)輸入第%d輛車的序號(hào):",i+1);
????????????sum[i]=s1.nextInt();//捕捉用戶輸入車的序號(hào)并存入數(shù)組
????????}
????????System.out.println("請(qǐng)輸入租車天數(shù):");
????????int?days=s1.nextInt();//捕捉用戶輸入的天數(shù)
????????System.out.println("您的賬單:");
????????new?carRentSystem?().bill(sum,cars,days);
????}else?{
????????????System.out.println("再見");
????????????System.exit(0);
????}
??}
??
??//生存賬單
??public?void?bill(int[]?sum,car[]?cars,int?days)?{
??????int?persons=0;//統(tǒng)計(jì)載客總數(shù)
??????double?weights=0;//統(tǒng)計(jì)載貨總數(shù)
??????int?rents=0;//統(tǒng)計(jì)總金額
??????System.out.println("***可載人的車有:");
??????for?(int?i?=?0;?i?<?sum.length;?i++)?{
??????????????//判斷這個(gè)序號(hào)的車是否是客車不是就跳過這次循環(huán)
??????????if?(sum[i]>2)?{
??????????????System.out.print(cars[sum[i]-1].carName+"?");
??????????????persons+=cars[sum[i]-1].persons;
??????????????rents+=cars[sum[i]-1].rent;
??????????}else?{
??????????????????continue;
??????????}
??????}
??????System.out.println("共載人:"+persons+"人");
??????System.out.println("***可載貨的車有:");?
??????for(int?i=0;i<?sum.length;?i++)?{?
??????????????if?(sum[i]<4)?{
??????????????????????System.out.print(cars[sum[i]-1].carName+"?");
??????????????????????weights+=cars[sum[i]-1].weights;
??????????????????????//防止皮卡的金額被二次計(jì)算
??????????????????????if?(sum[i]!=3)?{
??????????????????????????????rents+=cars[sum[i]-1].rent;
??????????????????????}
??????????????}
??????}
??????System.out.println("共載貨:"+weights+"噸");
??????System.out.println("租車總價(jià)格:"+rents*days+"元");
??}
}

代碼我都是從eclipse一行一行抄下來的(這個(gè)竟然直接粘貼會(huì)寫成一行),不過在這上面運(yùn)行不了,應(yīng)該是類名不對(duì)(他所有的類名都是HelloWorld的),不過我把運(yùn)行效果截圖了,求大佬幫我看看有什么可以優(yōu)化的地方。https://img1.sycdn.imooc.com//5b87d71a0001fa6d19201080.jpg

正在回答

15 回答

為什么我的super調(diào)用父類不行啊


0 回復(fù) 有任何疑惑可以回復(fù)我~

在請(qǐng)輸入第幾輛車的序號(hào)后面 應(yīng)該每一次都是用戶自己輸入的 不是只按圖片結(jié)果那樣顯示的吧?

0 回復(fù) 有任何疑惑可以回復(fù)我~

類名不得大寫嗎

1 回復(fù) 有任何疑惑可以回復(fù)我~

666

0 回復(fù) 有任何疑惑可以回復(fù)我~

你這個(gè)覺得其實(shí)已經(jīng)優(yōu)化過了,較之其他人的代碼,你這個(gè)還是很不錯(cuò)的

3 回復(fù) 有任何疑惑可以回復(fù)我~
首頁上一頁12下一頁尾頁

舉報(bào)

0/150
提交
取消

分享一下代碼求大佬給一點(diǎn)優(yōu)化思路

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)