实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx

上传人:b****1 文档编号:263067 上传时间:2023-04-28 格式:DOCX 页数:17 大小:59.96KB
下载 相关 举报
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第1页
第1页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第2页
第2页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第3页
第3页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第4页
第4页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第5页
第5页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第6页
第6页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第7页
第7页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第8页
第8页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第9页
第9页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第10页
第10页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第11页
第11页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第12页
第12页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第13页
第13页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第14页
第14页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第15页
第15页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第16页
第16页 / 共17页
实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx

《实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx》由会员分享,可在线阅读,更多相关《实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx(17页珍藏版)》请在冰点文库上搜索。

实验报告7面向对象程序设计Java15级计科0140何超健Word文档格式.docx

3.编写矩形类Rectangle。

area方法求矩形的面积,perimeter求矩形的周长。

编写用户程序TestRectangle,创建一个矩形,求该矩形的面积和周长并打印。

4.如图所示,写一个成绩类Score,包含英语、数学、语文、综合四科。

getTotalScore求总分,average求平均分。

编写用户程序TestScore,创建一成绩对象,并对各科赋值。

然后求总分和平均分。

5.编写学生类Student,包含学号,姓名,是否特殊考生和成绩等属性,成绩利用上题编写的Score类。

特殊考生总成绩加10分。

编写用户程序TestStudent,创建学生,修改其成绩,求其总分并打印,调用speak方法来理解重载。

实验步骤与内容(备注截图)

第一题:

packagep1;

publicclassPoint{

privatedoublex;

privatedoubley;

publicPoint()

{

this.x=0;

this.y=0;

}

publicPoint(doublex,doubley)

this.x=x;

this.y=y;

publicdoublegetX()

returnthis.x;

publicvoidsetX(doublex)

publicdoublegetY()

returnthis.y;

publicvoidsetY(doubley)

publicvoidmovePoint(doubledx,doubledy)

this.x=this.x+dx;

this.y=this.y+dy;

publicdoublegetDistance(Pointpoint)

doubleL=Math.sqrt((this.x-point.x)*(this.x-point.x)+(this.y-point.y)*(this.y-point.y));

returnL;

 

importjava.util.Scanner;

publicclassTestPoint{

publicstaticvoidmain(String[]args)

{

Pointp1=newPoint(0,0);

Pointp2=newPoint(0,0);

System.out.println("

输入两个点的新坐标"

);

Scannerscanner=newScanner(System.in);

System.out.print("

输入P1点坐标增加:

"

doublex=scanner.nextDouble();

doubley=scanner.nextDouble();

p1.movePoint(x,y);

输入P2点坐标增加:

doublexx=scanner.nextDouble();

doubleyy=scanner.nextDouble();

p2.movePoint(xx,yy);

P1X:

+p1.getX()+"

"

P1Y:

+p1.getY());

P2X:

+p2.getX()+"

P2Y:

+p2.getY());

P1P2点距:

+p1.getDistance(p2));

}

第二题:

packagep2;

publicclassCircle{

privatedoubler;

publicCircle()

this.r=1;

publicdoublegetR()

returnthis.r;

publicvoidsetR(doubler)

this.r=r;

publicdoublearea()

doubleS=3.14*r*r;

returnS;

publicdoubleperometer()

doubleD=3.14*2*r;

returnD;

publicclassTestCircle{

Circlecl=newCircle();

创建一个圆。

输入圆的半径:

doubler=scanner.nextDouble();

cl.setR(r);

圆的周长:

+cl.perometer());

圆的面积:

+cl.area());

第三题:

packagep3;

publicclassRectangle{

privatedoublewidth;

privatedoublelength;

publicRectangle()

this.width=1;

this.length=1;

publicdoublegetWidth()

returnthis.width;

publicvoidsetWidth(doublewidth)

this.width=width;

publicdoublegetLength()

returnthis.length;

publicvoidsetLength(doublelength)

this.length=length;

doubleS=width*length;

doubleD=2*(width+length);

publicclassTestRectangle{

Rectanglert=newRectangle();

创建一个矩形。

输入矩形的长:

doublel=scanner.nextDouble();

输入矩形的宽:

doublew=scanner.nextDouble();

rt.setLength(l);

rt.setWidth(w);

矩形的周长:

+rt.perometer());

矩形的面积:

+rt.area());

第四题:

packagep4;

publicclassScore{

privatedoublechinese;

privatedoublemath;

privatedoubleenglish;

publicScore()

this.chinese=0;

this.math=0;

this.english=0;

this.x=0;

publicScore(doublec,doublem,doublee,doublex)

this.chinese=c;

this.math=m;

this.english=e;

this.x=x;

publicdoublegetChinese()

returnthis.chinese;

publicvoidsetChinese(doublechinese)

this.chinese=chinese;

publicdoublegetMath()

returnthis.math;

publicvoidsetMath(doublemath)

this.math=math;

publicdoublegetEnglish()

returnthis.english;

publicvoidsetEnglish(doubleenglish)

this.english=english;

publicdoublegetX()

returnthis.x;

publicvoidsetX(doublex)

publicdoublegetTotalScore()

doublets=this.chinese+this.english+this.math+this.x;

returnts;

publicdoubleaverage()

doubleaver=(this.chinese+this.english+this.math+this.x)/4;

returnaver;

publicclassTestScore{

Scoresc=newScore();

创建成绩对象"

输入语文成绩:

sc.setChinese(scanner.nextDouble());

输入数学成绩:

sc.setMath(scanner.nextDouble());

输入英语成绩:

sc.setEnglish(scanner.nextDouble());

输入综合成绩:

sc.setX(scanner.nextDouble());

总分:

+sc.getTotalScore());

平均分:

+sc.average());

第五题:

packagep5;

importp4.*;

publicclassStudent{

privateStringid;

privateStringname;

privatebooleanspecial;

privateScorescore;

publicStudent()

this.id="

000"

;

this.name="

张三"

this.special=false;

publicStudent(Stringid,Stringname,booleansp,Scorescore)

this.score=score;

publicStringgetId()

returnthis.id;

publicvoidsetId(Stringid)

this.id=id;

}publicStringgetName()

returnthis.name;

publicvoidsetName(Stringname)

this.name=name;

publicbooleanisSpecial()

returnthis.special;

publicvoidsetSpecial(booleansp)

this.special=sp;

publicScoregetScore()

returnthis.score;

publicvoidsetScore(Scorescore)

publicvoidsetScore(doublechinese,doublemath,doubleenglish,doublex)

{

score.setChinese(chinese);

score.setMath(math);

score.setEnglish(english);

score.setX(x);

{booleana=true;

booleanb=false;

if(special==a)

return(score.getChinese()+score.getEnglish()+score.getMath()+score.getX()+10);

elseif(special==b)

return(score.getChinese()+score.getEnglish()+score.getMath()+score.getX());

else

return1;

publicvoidspeak()

无参。

publicvoidspeak(Stringcontent)

一参。

publicvoidspeak(Stringcontent,Stringlanguage)

二参。

publicclassTestStudent{

{Scoresc=newScore();

Stringlanguage="

Stringcontent="

Studentst=newStudent();

输入学生信息:

输入学生学号:

st.setId(scanner.nextLine());

输入学生姓名:

st.setName(scanner.nextLine());

学生是否为特殊考生:

(1为是,0为否)"

Stringi=scanner.next();

st.setSpecial(i.equals("

1"

));

Scannerinput=newScanner(System.in);

输入学生成绩:

doublechinese=input.nextDouble();

doublemath=input.nextDouble();

doubleenglish=input.nextDouble();

doublex=input.nextDouble();

Scoresco=newScore(chinese,math,english,x);

st.setScore(sco);

+st.getTotalScore());

System.out.println();

st.speak();

st.speak(content);

st.speak(content,language);

实验过程记录

记录实验中遇到的困难及解决方法:

困难:

第五题的Student类有点不会

解决方法:

问同学

实验结果记录以及与预期结果比较以及分析

结果和预期的差不多

总结以及新的体会

不熟练,大部分代码都是经过大量的时间琢磨,才勉强能弄好。

填写内容时,可把表格扩大。

实验的源程序代码(要有注释)附在表后。

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

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2