Java程序设计实验计算机软件及应用IT计算机专业资料

上传人:m**** 文档编号:53416626 上传时间:2022-02-10 格式:DOC 页数:18 大小:123KB
返回 下载 相关 举报
Java程序设计实验计算机软件及应用IT计算机专业资料_第1页
第1页 / 共18页
Java程序设计实验计算机软件及应用IT计算机专业资料_第2页
第2页 / 共18页
Java程序设计实验计算机软件及应用IT计算机专业资料_第3页
第3页 / 共18页
亲,该文档总共18页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
盒陂科扶亭院学生实验报告册(理工类)课程名称:学生学号:所属院部:专业班级:学生姓名:指导教师:2020学年第学期金陵科技学院教务处制 实验报告书写要求 实验报告原则上要求学生手写, 要求书写工整。 若因课程特点需 打印的,标题采用四号黑体,正文采用小四号宋体,单倍行距。纸张 一律采用 A4 的纸张。实验报告书写说明 实验报告中实验目的和要求、 实验仪器和设备、实验内容与过程、 实验结果与分析这四项内容为必需项。 教师可根据学科特点和实验具 体要求增加项目。填写注意事项(1)细致观察,及时、准确、如实记录。(2)准确说明,层次清晰。(3)尽量采用专用术语来说明事物。(4)外文、符号、公式要准确,应使用统一规定的名词和符号。(5)应独立完成实验报告的书写,严禁抄袭、复印,一经发现, 以零分论处 。实验报告批改说明 实验报告的批改要及时、认真、仔细,一律用红色笔批改。实验 报告的批改成绩采用五级记分制或百分制, 按金陵科技学院课堂教 学实施细则中作业批阅成绩评定要求执行。实验报告装订要求实验批改完毕后, 任课老师将每门课程的每个实验项目的实验报 告以自然班为单位、按学号升序排列,装订成册,并附上一份该门课 程的实验大纲。实验项目名称:面向对象编程实验实验学时:8同组学生姓名:实验地点:实验日期:实验成绩:批改教师:批改时间:实验 1 面向对象编程实验一、实验目的和要求(1理解Java概念、掌握JDK环境配置( 2)熟悉 Java 开发过程( 3)掌握 Java 面向对象编程基础:封装、继承、多态( 4)掌握 Java 接口编程,理解开发模式二、实验仪器和设备奔腾以上个人计算机, windows 操作系统。 配置好JDK环境,安装集成开发环境(Eclipse )三、实验内容与过程1、JDK环境配置2、面向对象的封装性范例:设计一个表示学生的类,里面有学生的三项成绩:计算机成绩、数学成绩、 英语成绩。 要求可以求总分、平均分、最高分、最低分,并且可以输出一个学生 的完整信息。代码如下:class Studentprivate String name ;private int age ;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.sum() / 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 ;elsethis.temp = new int1 ;public boolean add(int i) if(this.footthis.temp.length) this.tempthis.foot = i ; this.foot+ ; / return true ; /只是声明数组,但是大小未知/ 用于保存下一个的记录点/ 此时大小由外部决定/ 至少开辟一个空间/ 加入数据操作/ 还有空位/ 加入内容 改变长度 加入成功返回 trueelsereturn false ; public int getArray() return this.temp ;/ 加入失败/ 返回全部的数组class SortArray extends Arraypublic SortArray(int len)super(len) ;public int getArray()java.util.Arrays.sort(super.getArray() ; /排序操作return super.getArray() ;/ 返回的是排序后的内容class ReverseArray extends Arraypublic 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 ArrayDemopublic static void main(String 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.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) 构造方法:显式调用 GrandFather 类的构造方法,为 GrandFather 类的姓名 和年龄赋初始值。再为自己职业输入初始值。c) 方法 getFather(): 显式调用 GrandFather 类的 getGrandFather() ,再显示 父亲的相关信息 String 返回值(3) .创建主类,定义 main() 方法,构造 GrandFather 类的对象和 Father 类的对象,并分别显示详细信息。 思考:覆盖 将父类和子类的显示信息函数,写成统一的 getInfo 3、面向对象多态性 范例:计算柱体的体积。柱体体积计算公式是:底部面积乘以高度 柱体底部分为 圆形和矩形 要求:通过抽象类和多态实现package cn.jit.demo;abstract class Bottom / 父类抽象类 底部public abstract double calculatorArea();class CircleBottom extends Bottom/ 圆形底* 半径*/private double radius;Overridepublic 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 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;Overridepublic double calculatorArea() return sideA * sideB;public SquareBottom(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.bottom = 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 / 测试类public static void main(String args) Bottom bottom = new CircleBottom(1.0);double height = 1.0;ZhuTi zhuTi = new ZhuTi(bottom,height); double result = zhuTi.calculatorVolumn();System.out.println( 圆柱体的体积是: + result); bottom = new SquareBottom(1.0,1.0); zhuTi.changeBottom(bottom);result = zhuTi.calculatorVolumn();System.out.println( 立方体的体积是: + result); ,打印机等等也范例:接口和多态的应用,例如:电脑上实现了USB接 口,都实现了此标准。interface USBpublic void start() ; / 开始工作public void stop() ; /结束工作class Computerpublic static void plugin(USB usb)usb.start() ;usb.stop() ;class Flash implements USBpublic void start() System.out.pri ntln (Upublic void stop() System.out.pri ntln (U;class Print impleme nts USBpublic void start() System.out.pri ntl n(”public void stop() System.out.pri ntl n(”;public class In terPolDemo02public static void mai n(Stri ng args) Computer.plug in(new Flash(); Computer.plug in(new Prin t();盘开始工作。盘停止工作。打印机开始工作打印机停止工作IIIIIIII;对照范例,写出以下程序:(1) 乐器(In strume nt)的标准为弹奏(play),而乐器类型分为:钢琴(Pia no) 和小提琴(Violin ),各种乐器的弹奏方法各不同。编写代码实现不同乐 器的弹奏。(2)计算机模拟四、实验结果与分析(程序运行结果及其分析)五、实验体会实验项目名称: 实验学时:4同组学生姓名:实验地点:实验日期:实验成绩:批改教师:批改时间:实验 2 类集一、实验目的和要求(1)理解类集概念(2)熟悉 Collection 接口、List 接口、Set 接口和 Map接口( 3)掌握 ArrayList 类、 HashSet 类和 TreeSet 类( 4)理解 TreeMap、 HashMap二、实验仪器和设备奔腾以上个人计算机, windows 操作系统。配置好JDK环境,安装集成开发环境(Eclipse )三、实验内容与过程1、类集应用 范例:实现一个超市管理系统,要求可以添加货物,删除货物和查询货 物:。代码如下:public interface Goods 得到商品名称public String getName(); /public int getCount(); /得到商品数量public float getPrice(); /得到商品价格public class Book implements Goods private String name;private int count;private float price;public Book() public Book(String name, int count, float price) this.name = name; this.count = count;this.price = price;public String getName() return name;public void setName(String name) this.name = name;public int getCount() return count;public void setCount(int count) this.count = count;public float getPrice() return price;public void setPrice(float price) this.price = price;public boolean equals(Object obj) if (this = obj) return true; if (!(obj instanceof Book) return false;Book b = (Book) obj;if (b.name.equals(this.name) & b.count = this.count & b.price = this.price) return true; else return false;public int hashCode() return this.name.hashCode() + new Integer(this.count).hashCode() + new Float(this.price).hashCode();public String toString() return 书名: + this.name + ;书的价格: + this.price + 书的数量: + this.count;import java.util.ArrayList;import java.util.Iterator;import java.util.List;public class SuperMarket private List allGoods;public SuperMarket() this.allGoods = new ArrayList();public void add(Goods goods) this.allGoods.add(goods);public void remove(Goods goods) this.allGoods.remove(goods);public List search(String keyWord) List temp = new ArrayList(); Iterator iter = this.allGoods.iterator(); while (iter.hasNext() Goods g = iter.next();if (g.getName().indexOf(keyWord) != -1) temp.add(g);return temp;public List getAllGoods() return this.allGoods;import java.util.Iterator;import java.util.List;public class Test public static void main(String args) SuperMarket mak = new SuperMarket(); mak.add(new Book(Java, 2, 30.9f); mak.add(new Book(C+, 3, 10.9f); mak.add(new Book(JSP, 5, 80.9f); print(mak.search(J) ;mak.remove(new Book(Java, 2, 30.9f) ; print(mak.search(J) ;public static void print(List all) Iterator iter = all.iterator(); while (iter.hasNext() System.out.println(iter.next();对照范例写出如下题目:(1 )宠物商店,要求可以添加、删除和查找宠物(2) 实现以下两个关系A、一个学校可以有多个学生,所有学生属于一个学校B、一门课程可以有多个学生选,一个学生可以选多门课程四、实验结果与分析(程序运行结果及其分析)五、实验体会实验项目名称:Java 10 操作实验学时: 6同组学生姓名:实验地点:实验日期:实验成绩:批改教师:批改时间:实验 3 Java IO 操作一、实验目的和要求(1)理解输入输出流概念(2)掌握文件输入输出流(3)掌握键盘的输入、显示器的输出(4)理解其他输入输出流二、实验仪器和设备奔腾以上个人计算机, windows 操作系统。配置好JDK环境,安装集成开发环境(Eclipse )三、实验内容与过程1、编写类模拟命令 Copy 范例:实现文件的复制代码。参考代码如下: = new File ( “d: ”+ + ”demo.txt ”);/ 找到第一个文件的 File 对象= new File( “d: ”+ + ”cemo.txt ”); / 找到目标文件路径InputStream input = new (file1); / 输入流Outputstream output = new (file2); 输出流int temp = 0; /定义一个整数表示接收的内容while (temp = in put.read() != -1) /表示还有内容可以继续读output.write(temp);/ 写入数据input.close(); / 关闭output.close(); 关闭2、通过键盘的输入,实现简单的选项操作*xxxx管理系统*1 添加2 删除3 修改4 查询5 退出3 、编写一个简单管理系统,实现真实的操作四、实验结果与分析(程序运行结果及其分析)五、实验体会实验项目名称: JDBC实验学时:_6同组学生姓名:实验地点:实验日期:实验成绩:批改教师:批改时间:实验 4 JDBC一、实验目的和要求(1理解JDBC分类(2) 掌握JDBC数据库连接步骤(3) 掌握JDBC连接MySQl数据库代码(4) 理解JDBC连接其他数据库方式二、实验仪器和设备奔腾以上个人计算机, windows 操作系统。 配置好JDK环境,安装集成开发环境(Eclipse )三、实验内容与过程1安装MySQ数据库,配置好数据库创建一个数据库表,按要求给出详细的字段设计 pid name age birthday salary 主要操作:2、创建 Eclipse 项目,配置驱动包每个数据库厂商都会提供对 Java 开发技术的支持, 即都会提供对应 的 Java 驱动,也就是一个 jar 包主要操作:3、项目中建立一个详细例子,按照要求连接、操作、关闭数据库按照标准的步骤完成对MySQ数据库的操作主要代码:(添加、修改、删除和查询)4、试着连接其他类型数据库四、实验结果与分析(程序运行结果及其分析) 五、实验体会
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!