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

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

(1)設計一個表示二維平面上圓的類 Circle,有表示圓半徑的 protected類型的成員變量

2023-02-27 08:32 作者:酸奶公園  | 我要投稿

(1)

設計一個表示二維平面上圓的類

Circle

,有表示圓半徑的

protected

類型的成員變

radius

、獲取和設置

radius

值的

public

方法、計算圓面積的

public

方法。

(2)

設計一個表示圓柱體的類

Cylinder

,它繼承自類

Circle

,還包含有表示圓柱體高

protected

類型的成員變量

height

、獲取和設置

height

值的

public

方法、計算圓柱體體

積的

public

方法。

(3)

建立若干個

Cylinder

對象,輸出其半徑、高及其體積的值。

要求:

A

、每個類包含無參數(shù)和有參數(shù)的構造方法。構造方法用于對成員變量初始化,無

參數(shù)的構造方法將成員變量初始化為

0

值。

B

、子類的構造方法調(diào)用父類的構造方法,對父類中的成員變量初始化。

(較難)

import

java.lang.Math;

class

Circle{

protected

double

radius

;

public

Circle(){

radius

=0;}

public

Circle(

double

r

){

radius

=

r

;}

public

void

setRadius(

double

r

){

radius

=

r

;}

public

double

getRadius(){

return

radius

;}

public

double

area(){

return

Math.

PI

*

radius

*

radius

;}

}

class

Cylinder

extends

Circle{

protected

double

height

;

public

Cylinder(){

height

=0;}

public

Cylinder(

double

r

,

double

h

){

super

(

r

);

height

=

h

;

}

public

void

setHeight(

double

h

){

height

=

h

;}

public

double

getHeight(){

return

height

;}

public

double

volume(){

return

area()*

height

;}

}

public

class

testGEO {

public

static

void

main(String[]

args

) {

//

TODO

Auto-generated method stub

Cylinder

c1

=

new

Cylinder();

System.

out

.println(

"c1

的半徑為:

"

+

c1

.getRadius());

System.

out

.println(

"c1

的高為:

"

+

c1

.getHeight());

System.

out

.println(

"c1

的體積為:

"

+

c1

.volume());

Cylinder

c2

=

new

Cylinder(3,4);

System.

out

.println(

"c2

的半徑為:

"

+

c2

.getRadius());

System.

out

.println(

"c2

的高為:

"

+

c2

.getHeight());

System.

out

.println(

"c2

的體積為:

"

+

c2

.volume());

Cylinder

c3

=

new

Cylinder();

c3

.setRadius(6);

c3

.setHeight(8);

System.

out

.println(

"c3

的半徑為:

"

+

c3

.getRadius());

System.

out

.println(

"c3

的高為:

"

+

c3

.getHeight());

System.

out

.println(

"c3

的體積為:

"

+

c3

.volume());

}

}


(1)設計一個表示二維平面上圓的類 Circle,有表示圓半徑的 protected類型的成員變量的評論 (共 條)

分享到微博請遵守國家法律
西藏| 霸州市| 师宗县| 峨山| 黄龙县| 麻城市| 天镇县| 九江市| 来凤县| 邢台县| 北海市| 霍城县| 高阳县| 繁昌县| 广灵县| 丹巴县| 自治县| 安溪县| 怀安县| 教育| 剑河县| 晴隆县| 漳州市| 玛沁县| 文昌市| 阳信县| 郑州市| 勃利县| 章丘市| 察隅县| 丰都县| 吉首市| 德江县| 青岛市| 南阳市| 渭南市| 彰化县| 吉隆县| 璧山县| 松阳县| 龙胜|