Java程序设计实验5049.pdf





《Java程序设计实验5049.pdf》由会员分享,可在线阅读,更多相关《Java程序设计实验5049.pdf(22页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 学 生 实 验 报 告 册(理工类)课程名称:专业班级:学生学号:学生姓名:所属院部:指导教师:20 20 学年 第 学期 金陵科技学院教务处制 实验报告书写要求 实验报告原则上要求学生手写,要求书写工整。若因课程特点需打印的,标题采用四号黑体,正文采用小四号宋体,单倍行距。纸张一律采用 A4 的纸张。实验报告书写说明 实验报告中实验目的和要求、实验仪器和设备、实验内容与过程、实验结果与分析这四项内容为必需项。教师可根据学科特点和实验具体要求增加项目。填写注意事项(1)细致观察,及时、准确、如实记录。(2)准确说明,层次清晰。(3)尽量采用专用术语来说明事物。(4)外文、符号、公式要准确,应
2、使用统一规定的名词和符号。(5)应独立完成实验报告的书写,严禁抄袭、复印,一经发现,以零分论处。实验报告批改说明 实验报告的批改要及时、认真、仔细,一律用红色笔批改。实验报告的批改成绩采用五级记分制或百分制,按金陵科技学院课堂教学实施细则中作业批阅成绩评定要求执行。实验报告装订要求 实验批改完毕后,任课老师将每门课程的每个实验项目的实验报告以自然班为单位、按学号升序排列,装订成册,并附上一份该门课程的实验大纲。实验项目名称:面向对象编程实验 实验学时:8 同组学生姓名:实验地点:实验日期:实验成绩:批改教师:批改时间:实验 1 面向对象编程实验 一、实验目的和要求(1)理解 Java 概念、掌
3、握 JDK 环境配置(2)熟悉 Java 开发过程(3)掌握 Java 面向对象编程基础:封装、继承、多态(4)掌握 Java 接口编程,理解开发模式 二、实验仪器和设备 奔腾以上个人计算机,windows 操作系统。配置好 JDK 环境,安装集成开发环境(Eclipse)三、实验内容与过程 1、JDK 环境配置 2、面向对象的封装性 范例:设计一个表示学生的类,里面有学生的三项成绩:计算机成绩、数学成绩、英语成绩。要求可以求总分、平均分、最高分、最低分,并且可以输出一个学生的完整信息。代码如下:class Student private String name;private int age
4、;private float english;private float computer;private float math;public Student()public Student(String n,int a,float e,float c,float m)this.setName(n);this.setAge(a);this.setEnglish(e);this.setComputer(c);this.setMath(m);public float sum()return english+computer+math;public float avg()return this.su
5、m()/3;public float max()float max=computermath?computer:math;max=maxenglish?max:english;return max;public float min()float min=computermath?computer:math;min=min0)this.temp=new intlen;/此时大小由外部决定 else this.temp=new int1;/至少开辟一个空间 public boolean add(int i)/加入数据操作 if(this.footthis.temp.length)/还有空位 thi
6、s.tempthis.foot=i;/加入内容 this.foot+;/改变长度 return true;/加入成功返回 true else return false;/加入失败 public int getArray()/返回全部的数组 return this.temp;class SortArray extends Array public SortArray(int len)super(len);public int getArray()java.util.Arrays.sort(super.getArray();/排序操作 return super.getArray();/返回的是排序
7、后的内容 class ReverseArray extends Array public ReverseArray(int len)super(len);public int getArray()int rt=new intsuper.getArray().length;/根据大小开辟新数组 int count=rt.length-1;for(int x=0;xsuper.getArray().length;x+)rtcount=super.getArray()x;count-;return rt;public class ArrayDemo public static void main(S
8、tring args)ReverseArray arr=new ReverseArray(6);System.out.println(arr.add(3);System.out.println(arr.add(23);System.out.println(arr.add(1);System.out.println(arr.add(5);System.out.println(arr.add(6);System.out.println(arr.add(8);System.out.println(arr.add(11);System.out.println(arr.add(16);print(arr
9、.getArray();public static void print(int i)for(int x=0;xi.length;x+)System.out.print(ix+、);对照范例写出如下题目:(1).创建 GrandFather 类,其中包括 a)属性:姓名(name),年龄(age)b)方法 getGrandFather():显示爷爷的信息 c)构造方法:给爷爷的姓名,年龄赋值(2).创建 Father 类,继承 Grandfather 类 a)属性:除了继承爷爷的属性以外,还要增加自己的属性:“职业”(occupation)b)构造方法:显式调用父类的构造方法,为 Father
10、 类的姓名和年龄赋初始值。再为职业输入初始值。c)方法 getFather():显示父亲的相关信息(3).创建 ClassMain()类,定义 main()方法,构造 GrandFather 类的对象和Father 类的对象,并分别显示详细信息。3、面向对象多态性 范例:计算柱体的体积。柱体体积计算公式是:底部面积乘以高度 柱体底部分为 圆形和矩形 要求:通过抽象类和多态实现 package cn.jit.demo;abstract class Bottom /父类抽象类 底部 public abstract double calculatorArea();class CircleBottom
11、 extends Bottom /圆形底 /*半径 */private double radius;Override public double calculatorArea()return Math.PI*radius*radius;public double getRadius()return radius;public void setRadius(double radius)this.radius=radius;public CircleBottom(double radius)super();this.radius=radius;class SquareBottom extends
12、Bottom /矩形底 private double sideA;private double sideB;public double getSideA()return sideA;public void setSideA(double sideA)this.sideA=sideA;public double getSideB()return sideB;public void setSideB(double sideB)this.sideB=sideB;Override public double calculatorArea()return sideA*sideB;public Squar
13、eBottom(double sideA,double sideB)super();this.sideA=sideA;this.sideB=sideB;class ZhuTi /柱体类,完成形状的拼装 /*底 */private Bottom bottom;/*高 */private double height;/*计算体积 *return */public double calculatorVolumn()return bottom.calculatorArea()*height;public ZhuTi(Bottom bottom,double height)super();this.bo
14、ttom=bottom;this.height=height;public Bottom getBottom()return bottom;public void setBottom(Bottom bottom)this.bottom=bottom;public double getHeight()return height;public void setHeight(double height)this.height=height;public void changeBottom(Bottom bottom)this.bottom=bottom;public class VolumnTest
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 程序设计 实验 5049

限制150内