JAVA实验汇总Word格式文档下载.docx

上传人:b****4 文档编号:17076356 上传时间:2022-11-28 格式:DOCX 页数:35 大小:623.86KB
下载 相关 举报
JAVA实验汇总Word格式文档下载.docx_第1页
第1页 / 共35页
JAVA实验汇总Word格式文档下载.docx_第2页
第2页 / 共35页
JAVA实验汇总Word格式文档下载.docx_第3页
第3页 / 共35页
JAVA实验汇总Word格式文档下载.docx_第4页
第4页 / 共35页
JAVA实验汇总Word格式文档下载.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

JAVA实验汇总Word格式文档下载.docx

《JAVA实验汇总Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《JAVA实验汇总Word格式文档下载.docx(35页珍藏版)》请在冰豆网上搜索。

JAVA实验汇总Word格式文档下载.docx

2、熟悉数据类型类、Math类的常用属性和方法;

3、理解Applet类的主要方法如init()、start()、paint()、stop()、destroy(),能够使用HTML文件中<

PARAM>

标记向它所嵌入的Applet传递参数;

4、熟练掌握一维、二维数组的声明、创建、初始化和访问。

三、实验基本原理

实验一

importjava.applet.Applet;

importjava.awt.Graphics;

publicclassMDextendsApplet

{

/**

*

*/

privatestaticfinallongserialVersionUID=1L;

privateStrings="

"

;

privateintx;

privateinty;

publicvoidinit()

{

s=getParameter("

vstring"

);

x=Integer.parseInt(getParameter("

x"

));

y=Integer.parseInt(getParameter("

y"

}

publicvoidpaint(Graphicsg)

if(s!

=null)

g.drawString(s,x,y);

}

文本文档

<

HTML>

BODY>

APPLETcode="

MD.class"

height=200width=300>

PARAMname=vstringvalue="

我是来自HTML的参数"

>

PARAMname=XVALUE=50>

PARAMname=YVALUE=20>

/APPLET>

实验二

publicclassMD{

publicstaticvoidmain(Stringargs[]){

intmy_lqq[]=newint[10];

for(inti=0;

i<

my_lqq.length;

i++){

my_lqq[i]=(int)(Math.random()*100);

System.out.print(my_lqq[i]+"

"

}

System.out.println();

intmin=my_lqq[0];

i++)

{

if(min<

my_lqq[i])

min=my_lqq[i];

System.out.println("

随机数中最小值为:

+min);

intmax=my_lqq[0];

i++)

{if(max>

max=my_lqq[i];

}

随机数中最大值为:

+max);

intsum=0;

doublearvage=0;

sum+=my_lqq[i];

arvage=(float)(sum/10);

随机数的和为:

+sum);

随机数的平均值为:

+arvage);

}

MyEclipse8.0计算机及网络

①新建一个工程,然后新建一个类,在新建类的同时新建一个applet,再写入代码

②打开记事本,将文本格式的网页源代码写入,再保存为HTML格式

③将HTML格式的文件和class格式的文件放在一个文件夹中,再打开HTML网页即可

①新建一个工程,再新建一个类,写入代码

②运行代码即可

六、实验数据及处理结果

实验一:

编写程序与建立文本文档

以HTML形式与程序文件整合运行

出现结果

实验二:

通过第二个实验的上机操作,基本熟悉了软件操作和运行环境,可以很好的系统的通过编写程序而实现实验目的,也熟悉了数据类型类、Math类的常用属性和方法。

另外实验一必须把.class文件和.html文件放在一个文件夹中,网页才可显示出来。

实验报告三

1、定义一个表示学生的类Student,包括属性“学号”、“班号”、“姓名”、“性别”、“年龄”;

方法“获得学号”、“获得班号”、“获得姓名”、“获得性别”、“获得年龄”、“修改年龄”。

2、为Student类定义构造函数初始化所有属性,增加一个方法publicStringtoString(),把Student类对象的所有属性信息组合成一个字符串输出。

3、在main()中创建Student类对象,测试自定义类

1、熟练掌握如何自定义一个类。

2、熟练掌握如何定义构造函数,如何创建对象。

packageXML;

publicclassSTUDENT{

Stringid;

intclassnumber;

Stringname;

Stringsex;

intage;

publicSTUDENT(Stringid,intclassnumber,Stringname,Stringsex,intage)

this.id=id;

this.classnumber=classnumber;

this.name=name;

this.sex=sex;

this.age=age;

publicStringgetid(){

returnid;

publicintgetclassnumber(){

returnclassnumber;

publicStringgetsex(){

returnsex;

publicStringgetname(){

returnname;

publicintgetage(){

returnage;

publicbooleansetage(intnewage)

if(newage>

0&

&

newage<

100)

{

age=newage;

returntrue;

}else

returnfalse;

publicStringtoString(){

return"

学号是:

+getid()+"

\n班级号是:

+getclassnumber()+"

\n学生姓名是:

+getname()+"

\n学生性别是:

+getsex()+"

\n学生年龄是:

+getage();

publicstaticvoidmain(String[]args){

STUDENTaSTU=newSTUDENT("

6104114091"

141,"

啦啦啦"

"

女"

20);

System.out.println(aSTU.toString());

STUDENTbSTU=newSTUDENT("

System.out.println(bSTU.toString());

6、主要仪器设备及耗材

7、实验步骤

①新建一个工程project

②新建一个包package

③在包中新建一个class,写入上述代码

④运行完成

8、思考讨论题或体会或对改进实验的建议

实验报告四

一、实验项目名称

抽象、封装与类

(二)

二、实验目的

1、熟练掌握属性的定义和静态属性、最终属性的使用。

2、熟练掌握方法的定义和静态方法、抽象方法、最终方法的使用

三、实验基本原理

Java语言

四、主要仪器设备及耗材

五、实验步骤

编写一个程序,完成以下工作:

1、定义一个圆类Circle,成员变量有最终静态属性圆周率PI、半径radius,成员方法有自定义构造方法、获取半径getRadius()、修改半径updateRadius()、计算面积area()。

2、在定义一个圆锥类Taper,成员变量有底bottom、高height,成员方法有自定义构造方法、获得底圆半径getBottomR()、修改底圆半径updateBottomR()、获得高getHeight()、修改高updateHeight()、计算体积volume()。

3、最后写一测试类,测试自定义圆类Circle、圆锥类Taper是否正确。

六、实验数据及处理结果

classCircle{

staticdoublePI=3.14;

privatedoubleradius;

Circle(){

radius=0;

Circle(doubleradius){

this.radius=radius;

doublegetRadius(){

returnradius;

voidupdateRadius(intradius){

doublearea(){

returnPI*radius*radius;

classTaper{

doublePI=3.14;

privatedoublebottom;

privatedoubleheight;

Taper(){

bottom=0;

height=0;

Taper(doublebottom,intheight){

this.bottom=bottom;

this.height=height;

doublegetBottomR(){

returnMath.sqrt(bottom/PI);

voidupdateBottomR(doubleBottomR){

bottom=PI*BottomR*BottomR;

doublegetHeight(){

returnheight;

voidupdateHeight(doubleheight){

doublevolume(){

returnbottom*height/3;

}

publicclassxml{

publicstaticvoidmain(Stringargs[]){

Circlea1=newCircle

(2);

radius="

+a1.getRadius()+"

area="

+a1.area());

a1.updateRadius(3);

Taperb1=newTaper(3.14,4);

BottomR="

+b1.getBottomR()+"

height="

+b1.getHeight()+"

volume="

+b1.volume());

b1.updateBottomR

(2);

b1.updateHeight(3);

七、思考讨论题或体会或对改进实验的建议

Java语言程序设计

实验报告五

六、实验项目名称

继承与多态

(一)

七、实验目的

1、熟练掌握继承的实现方法;

2、熟练掌握this、super两个关键字的用法。

八、实验基本原理

九、主要仪器设备及耗材

一十、实验步骤

1、上机实践P103例5-2,理解父子类同名属性的使用;

2、上机实践P106例5-3,理解父子类同名方法即方法的覆盖的使用;

3、上机实践P109例5-5,理解this的用法;

4、上机实践P110例5-6,理解super的用法。

实践一:

publicclassHiddenField{

publicstaticvoidmain(Stringargs[])

D200_Cardmy200=newD200_Card();

my200.balance=50.0;

父类被隐藏的金额为:

+my200.getBalance());

if(my200.performDial())

System.out.println("

子类的剩余金额为:

+my200.balance);

abstractclassPhoneCard

doublebalance;

abstractbooleanperformDial();

doublegetBalance()

returnbalance;

abstractclassNumber_PhoneCardextendsPhoneCard

longcardNumber;

intpassword;

StringconnectNumber;

booleanconnected;

booleanperformConnection(longcn,intpw)

if(cn==cardNumber&

pw==password)

connected=true;

else

returnfalse;

classD200_CardextendsNumber_PhoneCard

doubleadditoryFee;

doublebalabce;

booleanperformDial()

if(balance>

(0.5+additoryFee))

balance-=(0.5+additoryFee);

实践二:

publicclassTestOverLoad{

publicstaticvoidmain(Stringargs[])

D200_Cardmy200=newD200_Card();

my200.balance=50.0;

子类自己的金额为:

if(my200.performDial())

System.out.println("

abstractclassPhoneCard

doublebalance;

abstractbooleanperformDial();

doublegetBalance()

returnbalance;

abstractclassNumber_PhoneCardextendsPhoneCard

longcardNumber;

intpassword;

StringconnectNumber;

booleanconnected;

booleanperformConnection(longcn,intpw)

if(cn==cardNumber&

{

connected=true;

returntrue;

}

else

returnfalse;

classD200_CardextendsNumber_PhoneCard

doubleadditoryFee;

doublebalabce;

booleanperformDial()

if(balance>

balance-=(0.5+additoryFee);

实践三:

publicclassTestThis{

LeafmyLeaf=newLeaf();

myLeaf=myLeaf.increment().increment().increment();

myLeaf.print();

classLeaf{

privateinti=0;

Leafincrement(){

i=i+1;

returnthis;

voidprint(){

i="

+i);

实践四:

publicclassTestSuper{

父亲被隐藏的金额为:

booleanperformConnection(longcn,intpw)

(0.5+

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 初中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1