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

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

整理了一下,把多個(gè)對(duì)象保存起來,這樣后期如果需要統(tǒng)計(jì)載人量或者載貨量相關(guān)的也可以。

package?com.car;

public?class?Car?{
????protected?String?carName;???//汽車名稱
????protected?Double?rent;??????//租金

????public?Car(String?carName,?double?rent){
????????this.carName?=?carName;
????????this.rent?=?rent;
????}

????public?String?getCarName(){
????????return?this.carName;
????}

????public?Double?getRent(){
????????return?this.rent;
????}
}


AManned

package?com.car;

/**
?*?載人汽車
?*/
public?class?AManned?extends?Car{
????protected?int?personCount;
????public?AManned(String?carName,?double?rent,?int?personCount){
????????super(carName,?rent);
????????this.personCount?=?personCount;
????}

????public?int?getPersonCount(){
????????return?this.personCount;
????}
}


ATruck:

package?com.car;

/**
?*?貨車
?*/
public?class?ATruck?extends?Car{
????protected?int?productCount;
????public?ATruck(String?carName,?double?rent,?int?productCount){
????????super(carName,?rent);
????????this.productCount?=?productCount;
????}

????public?int?getProductCount(){
????????return?this.productCount;
????}
}


AMulti:

package?com.car;

/**
?*?多功能汽車
?*/
public?class?AMulti?extends?Car{
????protected?int?productCount;
????protected?int?personCount;
????public?AMulti(String?carName,?double?rent,?int?personCount,??int?productCount){
????????super(carName,?rent);
????????this.productCount?=?productCount;
????????this.personCount?=?personCount;
????}

????public?int?getPersonCount(){
????????return?this.personCount;
????}

????public?int?getProductCount(){
????????return?this.productCount;
????}
}


index:

package?com.car;
import?java.util.Scanner;

public?class?index?{
????public?static?void?main(String[]?args){
????????//引導(dǎo)語
????????System.out.println("歡迎使用租車系統(tǒng)");
????????System.out.println("您是否要租車?1-是,0-否");
????????Scanner?input?=?new?Scanner(System.in);
????????int?isRent?=?input.nextInt();???????//是否租車
????????if?(isRent?==?1)?{
????????????System.out.println("您可租車的類型和價(jià)目表:");
????????????System.out.println("序號(hào)?汽車名稱?租金?容量");

????????????//聲明所有汽車并顯示
????????????Car[]?cars?=?{
????????????????????new?AManned("奧迪",500,?4),
????????????????????new?AManned("馬自達(dá)",400,?4),
????????????????????new?AMulti("皮卡雪",450,?4,?2),
????????????????????new?AManned("金龍",800,?20),
????????????????????new?ATruck("松花江",?400,?4),
????????????????????new?ATruck("依維柯",1000,?20)
????????????};
????????????for?(int?i?=?0;?i?<?cars.length;?i++)?{
????????????????int?index?=?i+1;
????????????????if?(cars[i]?instanceof?AManned)?{
????????????????????//載人
????????????????????AManned?car?=?(AManned)?cars[i];
????????????????????System.out.println(
????????????????????????????index?+?"?"+
????????????????????????????car.getCarName()+?"?"+
????????????????????????????car.getRent()+?"元/天?"+
????????????????????????????"載人:"+?car.getPersonCount()+?"人?"
????????????????????);
????????????????}?else?if(cars[i]?instanceof?ATruck)?{
????????????????????//載貨
????????????????????ATruck?car?=?(ATruck)?cars[i];
????????????????????System.out.println(
????????????????????????????index?+"?"+
????????????????????????????car.getCarName()+?"?"?+
????????????????????????????car.getRent()+?"元/天?"?+
????????????????????????????"載貨:"+?car.getProductCount()+"噸"
????????????????????);
????????????????}?else?{
????????????????????AMulti?car?=?(AMulti)?cars[i];
????????????????????System.out.println(
????????????????????????????index+?"?"+
????????????????????????????car.getCarName()+?"?"?+
????????????????????????????car.getRent()+?"元/天?"?+
????????????????????????????"載人:"+car.getPersonCount()+?"人?"+
????????????????????????????"載貨:"+car.getProductCount()+"噸");
????????????????}
????????????}

????????????//選擇要租的車,并記錄下來
????????????System.out.println("請(qǐng)選擇要租車的數(shù)量:");
????????????int?carsCount?=?input.nextInt();
????????????Car[]?chooseCar?=?new?Car[carsCount];
????????????for?(int?j?=?0;?j?<?carsCount;?j++)?{
????????????????int?cycle?=?j+1;
????????????????System.out.println("請(qǐng)選擇第"+?cycle?+"輛車:");
????????????????int?carNum?=?input.nextInt();
????????????????chooseCar[j]?=?cars[carNum-1];
????????????}

????????????//選擇租車天數(shù),并計(jì)算出租金
????????????System.out.println("請(qǐng)輸入要租的天數(shù):");
????????????int?days?=?input.nextInt();
????????????double?singleSum?=?0;
????????????double?sum?=?0;
????????????for?(Car?aCar:?chooseCar)?{
????????????????singleSum?+=?aCar.getRent();
????????????}
????????????sum?=?singleSum?*?days;
????????????System.out.println("您的租金是:"+sum);

????????}
????}
}


正在回答

12 回答

AManned?car?=?(AManned)?cars[i];

樓主,這個(gè)是干什么的啊,沒看懂!

是調(diào)用數(shù)組里的對(duì)象嗎

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

Minenami

強(qiáng)制類型轉(zhuǎn)換
2020-01-14 回復(fù) 有任何疑惑可以回復(fù)我~

大佬,請(qǐng)收下我的膝蓋!

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

舉報(bào)

0/150
提交
取消

整理了一下,把多個(gè)對(duì)象保存起來,這樣后期如果需要統(tǒng)計(jì)載人量或者載貨量相關(guān)的也可以。

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

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

幫助反饋 APP下載

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

公眾號(hào)

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