2010新Java程序设计实验报告.doc

上传人:jian****018 文档编号:9149276 上传时间:2020-04-03 格式:DOC 页数:10 大小:39.50KB
返回 下载 相关 举报
2010新Java程序设计实验报告.doc_第1页
第1页 / 共10页
2010新Java程序设计实验报告.doc_第2页
第2页 / 共10页
2010新Java程序设计实验报告.doc_第3页
第3页 / 共10页
点击查看更多>>
资源描述
Java程序设计实验报告学号: 1106840211 姓名:周磊 座位号: 实验日期:2012年12月15日【实验名称】: JDK配置与开发工具的使用【实验目的】:1 熟悉JDK开发环境。2 熟悉EditPlus编辑器或Eclipse等开发环境的使用。3 掌握Java Application的程序结构和开发过程。【实验内容及要求】:1 JDK安装。2 设置环境变量。3 分别运用EditPlus和Eclipse编写并运行一个简单的“Hello World!”应用程序。 【程序输出结果与结果分析】:Hello World!【自评分及理由,自己的体会和收获】:相对比叫而言,用EditPlus比较顺手,操作起来较方便,用Eclipse不太熟练。可能是Eclipse是英文版,而EditPlus是中文版的缘故。不过Eclipse的功能很多。【程序代码】:class HelloWorld public static void main(String args) System.out.println(Hello World!);Java程序设计实验报告学号: 1106840211 姓名:周磊 座位号: 实验日期:2012年12月22日【实验名称】: 类和对象的应用【实验目的】:1 掌握各种数据类型及其使用方法。2 掌握分支语句if、switch和循环语句for、while、do-while的应用。3 掌握类的声明和对象的创建。4 掌握方法的定义、调用和构造器的使用。【实验内容及要求】:1 分别使用if-else-if语句和switch语句编程,确定某一月在哪个季节。2 分别使用while、do-while和for语句编程,求1100的和。3 使用break语句实现记数:从1100,当数到78时程序终止。4 编程创建一个Box类,在其中定义三个变量表示一个立方体的长、宽和高,再定义一个方法setDemo对这三个变量进行初始化,然后定义一个方法求立方体的体积。创建一个对象,求给定尺寸的立方体的体积。【程序输出结果与结果分析】:1:输入1 输出winter2:50503:数从1到774:60.0【自评分及理由,自己的体会和收获】:1 学会了怎样用Scanner函数输入所需数据。2 较为熟练的使用了switch-case语句.for循环语句。While等语句。3 学会了怎样编写有关类和对象的程序。【程序代码】:import java.util.*;class MonthName public static void main(String args) Scanner sc=new Scanner(System.in); int i=sc.nextInt(); switch(i) case 12: case 1: case 2: System.out.println(winter); break; case 3: case 4: case 5: System.out.println(spring); break; case 6: case 7: case 8: System.out.println(summer); break; default: System.out.println(autumn); System.out.println(i); class MonthName public static void main(String args) for (int i=1; i13 ; i+ ) if (i=1|i=2|i=12) System.out.println(winter); else if (i=3|i=4|i=5) System.out.println(spring); else if (i=6|i=7|i=8) System.out.println(summer); else if (i=9|i=10|i=11) System.out.println(autumn); class PartialSum public static void main(String args) int s=0; int i=1; while(i=100) s=s+i; i=i+1; System.out.println(s); class PartialSum public static void main(String args) int s=0; int i=1; do s+=i+; while(i=100); System.out.println(s); class PartialSum public static void main(String args) int s=0; for (int i=1;i=100 ;i+ ) s=s+i; System.out.println(s); class Count public static void main(String args) for (int i=1; i=78) break; else System.out.println(i); class Box double width,height,depth; public void setDemo(double a,double b,double c) width=a; height=b; depth=c; public double Volume() double v; v=width*height*depth; return v; public static void main(String args) Box b=new Box(); b.width=3.0; b.height=4.0; b.depth=5.0; System.out.println(b.Volume(); Java程序设计实验报告学号: 1106840211 姓名:周磊 座位号: 实验日期:2012年12月30日【实验名称】: 继承与多态的应用【实验目的】:1 掌握类的继承方法。2 掌握变量的继承和覆盖。3 掌握方法的继承、重载和覆盖。4 掌握扩展类中构造器的使用。【实验内容及要求】:1 编写一个Java应用程序,设计一个汽车类Vehicle,包含的成员属性有:车轮个数wheels和车重weight。小车类Car是Vehicle的子类,其中包含属性载人数passenger_load。卡车Truck是Vehicle的子类,其中包含载人数passenger_load和载重量payload。要求每个类都有相关数据的输出方法。2 运行程序,理解成员变量的继承与隐藏。【程序输出结果与结果分析】:wheels: 4,weight:650wheels: 4,weight: 560.0,passenger_load:6 wheels: 4,weight: 670.0,passenger_load:40,payload:100.0【自评分及理由,自己的体会和收获】:1 学会使用类的继承了来创建新类 。2 java里只允许单继承。3 一个java程序可以有多个类,所以可以有多个main函数,要执行哪个的main函数九保存为该类的名字。4 若A继承B,则A继承了B的所有属性和方法,B可以有自己的特殊属性,可以重写方法。【程序代码】:class Vehicle int wheels; double weight; public Vehicle() public Vehicle(int wheels,double weight) this.wheels=wheels; this.weight=weight; public void show() System.out.println(wheels:+wheels+,weight:+weight); class Car extends Vehicle private int passenger_load; public Car(int wheels,double weight, int passenger_load)this.wheels=wheels; this.weight=weight; this.passenger_load=passenger_load; public void show() System.out.println(wheels:+wheels+,weight:+weight+,passenger_load:+passenger_load); class Truck extends Vehicle private int passenger_load; private double payload; Truck() public Truck(int wheels,double weight,int passenger_load,double payload) this.wheels=wheels; this.weight=weight; this.passenger_load=passenger_load; this.payload=payload; public void show() System.out.println(wheels:+wheels+,weight:+weight+,passenger_load:+passenger_load+,payload+payload); class Test public static void main(String args) Vehicle v=new Vehicle(4,650); Car c=new Car(4,560.0, 6); Truck t=new Truck(4,670.0,40,100.0); v.show(); c.show(); t.show(); Java程序设计实验报告学号: 1106840211 姓名:周磊 座位号: 实验日期:2013年1月8日【实验名称】: 接口的使用【实验目的】:1 掌握接口的含义和声明。2 掌握单继承和多继承的概念。【实验内容及要求】:1 定义一个接口Area,其中包含一个计算面积的抽象方法calculateArea(),然后设计MyCircle和MyRectangle两个类都实现这个接口中的方法calculateArea(),分别计算圆和矩形的面积。2 运行程序,理解使用接口的环境和方法。【程序输出结果与结果分析】:314.159265358979312.0【自评分及理由,自己的体会和收获】:1 接口由抽象方法和常量组成,是一种特殊的类。2 实现一个接口,类必须实现接口中的所有方法,关键字为implements。3 接口支持多继承,所以达到同一接口可能存在多条途径。4 使用接口可减少代码的书写。【程序代码】:interface Area double calculateArea();class MyCircle implements Area double r=10; public double calculateArea() return Math.PI*r*r; class MyRectangle implements Area double width=3; double length=4; public double calculateArea() return width*length; class Test public static void test(Area a) System.out.println(a.calculateArea(); public static void main(String args) MyCircle c=new MyCircle(); MyRectangle re=new MyRectangle(); test(c); test(re);
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 管理文书 > 工作总结


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

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


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