五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

2、有一個(gè)收音機(jī)(Radio),需要安裝電池(Battery)才能夠打開(openRadio())。電池

2023-03-09 11:46 作者:酸奶公園  | 我要投稿

1、有一個(gè)收音機(jī)(Radio),需要安裝電池(Battery)才能夠打開(openRadio())。電池原有100格(electricityAmount=100)電。請模擬出收音機(jī)在安裝上“南孚”電池,打開收音機(jī)后,就消耗了10格電的場景。

?

?

package?面向?qū)ο蠡靖拍罹C合練習(xí);

?

public?class?課堂練習(xí)題2 {

?

public?static?void?main(String[] args) {

// TODO?Auto-generated method stub

class?Radio?{

????private?int?electricityAmount;

?

????public?Radio()?{

????????this.electricityAmount?= 0;

????}

?

???

?

????public?void?openRadio()?{

????????if?(this.electricityAmount?> 0) {

????????????System.out.println("Radio is open.");

????????} else?{

????????????System.out.println("Battery has no electricity.");

????????}

????}

}

?

class?Battery?{

????private?int?electricityAmount;

?

????public?Battery()?{

????????this.electricityAmount?= 100;

????}

?

????public?int?getElectricityAmount()?{

????????return?this.electricityAmount;

????}

}

?


}

?

}

?

?

```

+----------+ +---------+

| Radio | | Battery |

+----------+ +---------+

| | | |

| | | |

| openRadio() <------+ | |

+----------+ | | |

| | | |

electricityAmount=100 | addBattery()

| | |

electricityAmount=100

|

consumeElectricity()

|

electricityAmount=90

```

注釋:

- Radio類有一個(gè)openRadio()方法用于打開收音機(jī),以及一個(gè)consumeElectricity()方法用于消耗電池電量。

- Battery類有一個(gè)屬性electricityAmount表示電池電量,以及一個(gè)addBattery()方法用于安裝電池。

- Radio類與Battery類之間是一對一的關(guān)系。


2、有一個(gè)收音機(jī)(Radio),需要安裝電池(Battery)才能夠打開(openRadio())。電池的評論 (共 條)

分享到微博請遵守國家法律
伊通| 轮台县| 垣曲县| 习水县| 普安县| 固安县| 东乡族自治县| 凌源市| 旅游| 通海县| 瑞安市| 原平市| 咸阳市| 台东县| 宁明县| 高安市| 历史| 封开县| 柳林县| 屏东市| 巴彦淖尔市| 罗山县| 阳高县| 郴州市| 定兴县| 安仁县| 江油市| 沈丘县| 博爱县| 玉门市| 繁昌县| 封开县| 韶关市| 和田市| 农安县| 驻马店市| 荔浦县| 西宁市| 仁寿县| 崇明县| 柘荣县|