大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國(guó)咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學(xué)習(xí)攻略 Java學(xué)習(xí) Java接口編程練習(xí)題,趕緊收藏起來吧

Java接口編程練習(xí)題,趕緊收藏起來吧

更新時(shí)間:2020-09-15 16:53:21 來源:動(dòng)力節(jié)點(diǎn) 瀏覽5803次

題目1:

創(chuàng)建Person接口(即“人”),它有setData()和getData()方法對(duì)“人”屬性name、sex和birthday賦值和獲得這些屬性組成的字符串信息。創(chuàng)建類Student實(shí)現(xiàn)Person接口,并對(duì)自己的“學(xué)生”屬性的成員變量sID、speciality設(shè)置值和獲得它們值所組成的字符串信息。

代碼:

People.java(接口)

package?com.interfaces;
public?interface?People?{
public?void?setData(String?name,String?sex,String?birthday);
public?String?getData();
}
Student.java(實(shí)現(xiàn)接口的類)

package?com.interfaces.impl;
?
import?com.interfaces.People;
?
public?class?Student?implements?People?{
	?private?String?name;??
	?private?String?sex;??
	?private?String?birthday;??
	?private?String?sID="2014";??
	?private?String?speciality="寫代碼";??
	@Override
	public?void?setData(String?name,?String?sex,?String?birthday)?{
		//?TODO?Auto-generated?method?stub
???????this.name=name;
???????this.sex=sex;
???????this.birthday=birthday;
	}
?
	@Override
	public?String?getData()?{
		//?TODO?Auto-generated?method?stub
	????return?"名字:?"?+?name?+?",性別:?"?+?sex?+?",生日:?"?+?birthday?+?",ID:?"?+?sID?+?",專長(zhǎng):?"?+speciality;
	}
?
	public?static?void?main(String[]?args)?{
		//?TODO?Auto-generated?method?stub
???????People?Yantai=new?Student();
???????Yantai.setData("海哥",?"男",?"2017年2月19日");
???????System.out.println(Yantai.getData());
???????
	}
?
}

題目2:

編寫程序,求柱體的體積:

(1)、為柱體的底面設(shè)計(jì)一個(gè)接口Geometry,包含計(jì)算面積的方法getArea();

(2)、為柱體設(shè)計(jì)類pillar,要求:

a)有兩個(gè)成員變量,底面和高度。底面是任何可以計(jì)算面積的幾何形狀。

b)實(shí)現(xiàn)構(gòu)造方法,對(duì)成員變量賦值。

c)包含成員方法,計(jì)算柱體pillar的體積。

(3)、編寫測(cè)試類圓形類、矩形類實(shí)現(xiàn)Geometry接口,編寫測(cè)試類Test,分別用圓形、矩形作為柱體的底面,并計(jì)算其體積。

代碼:

Geometry.java(接口)

package?com.interfaces;
public?interface?Geometry?{
public?double?getArea();
}
Test.java(接口實(shí)現(xiàn)類)

package?com.interfaces.impl;
?
import?com.interfaces.Geometry;
?
public?class?Test?{
	public?static?void?main(String[]?args)?{
		//?TODO?Auto-generated?method?stub
		?Pillar?pillar;????
?????????Geometry?bottom;????
????????????????
?????????bottom?=?new?Rect(10,?5);?//接口實(shí)現(xiàn)方法???
?????????pillar?=?new?Pillar(bottom,?5);????
?????????System.out.println("矩形底的柱體的體積:"?+?pillar.Volume());????
????????????????
?????????bottom?=?new?Circle(5);?
?????????pillar?=?new?Pillar(bottom,?5);????
?????????System.out.println("圓形底的柱體的體積:"?+?pillar.Volume());??
	}
	
	/*
	?*?柱體設(shè)計(jì)類
	?*/
	class?Pillar{
		Geometry?bottom;??
	????double?height;??
	????public?Pillar(Geometry?bottom,?double?height){??
	????????this.bottom=bottom;??
	????????this.height=height;??
	????}??
	????public?double?Volume(){??
	????????return?bottom.getArea()*this.height;???
	????}??
	}
	
	/*
	?*?矩形測(cè)試類
	?*/
	class?Circle?implements?Geometry{
????????double?radius;
		public?Circle(double?radius){??
	????????this.radius?=?radius;??
	????}??
		public?double?getArea()?{
			//?TODO?Auto-generated?method?stub
			return?Math.PI*this.radius*this.radius;
		}
		
	}
	
	/*
	?*?圓形測(cè)試類
	?*/
	class?Rect?implements?Geometry{??
	????double?wide,length;??
	????public?Rect(double?wide,?double?length){??
	????????this.wide?=?wide;??
	????????this.length?=?length;??
	????}??
	????public?double?getArea()?{??
	????????return?wide*length;??
	????}??
	}??
}

以上就是動(dòng)力節(jié)點(diǎn)java培訓(xùn)機(jī)構(gòu)的小編針對(duì)“Java接口編程練習(xí)題,趕緊收藏起來吧”的內(nèi)容進(jìn)行的回答,希望對(duì)大家有所幫助,如有疑問,請(qǐng)?jiān)诰€咨詢,有專業(yè)老師隨時(shí)為你服務(wù)。

提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)

  • 全國(guó)校區(qū) 2025-10-10 搶座中
免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 青草视频在线 | 五月情视频在线观看 | 亚洲视频久久 | 色爱综合网欧美 | 女人18毛片特级一级免费视频 | 好吊妞乱淫欧美 | 99精品这里只有精品高清视频 | 亚洲最大在线视频 | 国产香蕉一区二区精品视频 | 亚洲国产精品成人久久 | 亚洲欧洲成人 | 国产一区中文字幕在线观看 | 亚洲999 | 日韩在线国产 | 亚洲一区二区欧美日韩 | 欧美国产综合 | 一级免费视频 | 一级床上爽高清播放 | 色偷偷亚洲第一综合 | 国产视频www | 日韩中文字幕在线不卡 | 久久免费视频99 | 亚州视频在线 | 91精品国产福利尤物免费 | 日韩欧美在线看 | 性生生活网站免费 | 亚洲免费黄色网 | 亚洲一区国产 | www.日韩视频| 欧美日一级片 | 97免费视频在线观看 | 神马影院午夜我不卡 | 国产精品99久久久久久宅男 | 青青青在线视频 | 欧美精品99| 中国一级毛片aaa片 中国一级毛片录像 | 夜夜女人国产香蕉久久精品 | 日日摸天天摸狠狠摸视频 | 亚洲伊人tv综合网色 | 亚洲美女激情 | 天天摸夜夜添久久精品麻豆 |