国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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())。電池的評論 (共 條)

分享到微博請遵守國家法律
宁陵县| 洪湖市| 商河县| 古田县| 彩票| 仁布县| 区。| 扎囊县| 南岸区| 邵武市| 宜川县| 康平县| 兴宁市| 子洲县| 哈尔滨市| 舟曲县| 靖州| 枣阳市| 三亚市| 延安市| 黄龙县| 周宁县| 宝兴县| 红原县| 杂多县| 绥宁县| 石泉县| 固阳县| 旬阳县| 柘城县| 庄河市| 东乡县| 潜江市| 山东省| 奉化市| 广南县| 南充市| 延吉市| 泸水县| 三台县| 左权县|