最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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類型的成員變量的評論 (共 條)

分享到微博請遵守國家法律
五原县| 蒙自县| 文化| 建瓯市| 高邮市| 邹平县| 太康县| 五河县| 闻喜县| 西和县| 喀喇| 黄石市| 汉源县| 汶川县| 岳阳市| 天柱县| 布拖县| 龙井市| 河北省| 大足县| 南安市| 随州市| 股票| 霞浦县| 武山县| 略阳县| 勐海县| 涿州市| 固始县| 柞水县| 永康市| 什邡市| 成安县| 枣庄市| 若尔盖县| 肇州县| 太原市| 上虞市| 禹州市| 越西县| 奇台县|