




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
面向对象程序设计(Java)实验报告福建工程学院软件学院实验报告2016 2017 学年度第 一 学期 任课教师: 陈丽晖课程名称面向对象程序设计(Java)班级物联网(本)1401座号31姓名谢学伟实验题目实验时间实验开始日期:2016.09.20实验提交日期:实验目的、要求1. 如图所示,编写类Point。Point包含两个成员变量x、y分别表示x和y坐标。movePoint方法实现点的位置的移动(dx,dy表示相对位移)。getDistance求该点与另外一个点的距离。编写用户程序TestPoint,创建两个Point对象p1,p2,分别调用movePoint()方法后,打印p1和p2的坐标,然后求p1和p2之间的距离2.如图所示,编写圆类Circle。area方法求圆的面积,perimeter求圆的周长。编写用户程序TestCircle,创建一个圆,求圆的面积和周长并打印出来。3.编写矩形类Rectangle。area方法求矩形的面积,perimeter求矩形的周长。编写用户程序TestRectangle,创建一个矩形,求该矩形的面积和周长并打印。4.如图所示,写一个成绩类Score,包含英语、数学、语文、综合四科。getTotalScore求总分,average求平均分。编写用户程序TestScore,创建一成绩对象,并对各科赋值。然后求总分和平均分。5.编写学生类Student,包含学号,姓名,是否特殊考生和成绩等属性,成绩利用上题编写的Score类。特殊考生总成绩加10分。编写用户程序TestStudent,创建学生,修改其成绩,求其总分并打印,调用speak方法来理解重载。实验步骤与内容(备注截图)1. public class Point private double x;private double y;private double newX;private double newY;public Point() / TODO Auto-generated constructor stubpublic Point(double x, double y) this.x = x;this.y = y;public double getX() return x;public void setX(double x) this.x = x;public double getY() return y;public void setY(double y) this.y = y;public void movePoint(double dx,double dy)this.newX=x+dx;this.newY=y+dy;public double getDinstance()double dinstance;dinstance=Math.sqrt(Math.pow(Math.abs(x-newX),2)+Math.pow(Math.abs(y-newY),2);return dinstance;public class PointTest public static void main(String args) Scanner scanner=new Scanner(System.in);Point point=new Point();while (true) System.out.println(请输入原始点位置);System.out.println(原始点X坐标);double x = scanner.nextDouble();System.out.println(原始点y坐标);double y = scanner.nextDouble();System.out.println(请输入移动的X值);double moveX=scanner.nextDouble();System.out.println(请输入移动的Y值);double moveY=scanner.nextDouble();point.movePoint(moveX, moveY);System.out.println(两点之间的距离为:+point.getDinstance();2. public class Circle private double r;private double area;public Circle() public double getR() return r;public void setR(double r) this.r = r;public double getArea() return area;public void setArea(double area) this.area = area;public double perimeter(double r)double area=Math.PI*r*r;return area;public double zhouChang(double r)double zhouChang;return zhouChang=Math.PI*r*2;public class CircleTest public static void main(String args) Circle circle=new Circle();Scanner scanner=new Scanner(System.in);while (true) System.out.println(请输入圆形的半径);double r=scanner.nextDouble();System.out.println(圆形的面积是:+circle.perimeter(r);System.out.println(圆形的周长是:+circle.zhouChang(r);3. public class Rectangle private double length;private double width;public Rectangle() / TODO Auto-generated constructor stubpublic double getLength() return length;public void setLength(double length) this.length = length;public double getWidth() return width;public void setWidth(double width) this.width = width;public double area()return length*width;public double perimeter()return length*2+width*2;public class RectangleTest public static void main(String args) Scanner scanner=new Scanner(System.in);Rectangle rectangle=new Rectangle();while (true) System.out.println(请输入矩形的长:);double length=scanner.nextDouble();System.out.println(请输入矩形的宽:);double width=scanner.nextDouble();rectangle.setLength(length);rectangle.setWidth(width);System.out.println(矩形的面积是:+rectangle.area();System.out.println(矩形的周长是:+rectangle.perimeter();4.public class Score private double Chinese;private double Math;private double English;private double Zonghe;public Score() public Score(double chinese, double math, double english, double zonghe) Chinese = chinese;Math = math;English = english;Zonghe = zonghe;public double getChinese() return Chinese;public void setChinese(double chinese) Chinese = chinese;public double getMath() return Math;public void setMath(double math) Math = math;public double getEnglish() return English;public void setEnglish(double english) English = english;public double getZonghe() return Zonghe;public void setZonghe(double zonghe) Zonghe = zonghe;public double getTotalScore()double totle=Chinese+English+Math+Zonghe;return totle;public double average()double average=(Chinese+English+Math+Zonghe)/4;return average;public class ScoreTest public static void main(String args) Scanner scanner=new Scanner(System.in);System.out.println(请输入语文成绩:);double Chinese=scanner.nextDouble();System.out.println(请输入数学成绩:);double Math=scanner.nextDouble();System.out.println(请输入英语成绩);double English=scanner.nextDouble();System.out.println(请输入综合成绩:);double zonghe=scanner.nextDouble();Score score=new Score();score.setChinese(Chinese);score.setEnglish(English);score.setMath(Math);score.setZonghe(zonghe);System.out.println(总成绩:+score.getTotalScore();System.out.println(平均分:+score.average();5. public class Student private String id;private String name;private boolean special=false;private Score score;public Student() / TODO Auto-generated constructor stubpublic Student(String id, String name, boolean special, Score score) this.id = id; = name;this.special = special;this.score = score;public String getId() return id;public void setId(String id) this.id = id;public String getName() return name;public void setName(String name) = name;public boolean isSpecial() return special;public void setSpecial(boolean special) this.special = special;public Score getScore() return score;public void setScore(Score score) this.score = score;public void apeak()public void speak(String content)public void speak(String content,String language)Overridepublic String toString() return Student id= + id + , name= + name + , score= + score+ , special= + special + ;public class StudentTest /* * param args */public static void main(String args) Scanner scanner=new Scanner(System.in);boolean flag=false;System.out.println(请输入学生id:);String id=scanner.nextLine();System.out.println(请输入学生姓名:);String name=scanner.nextLine();System.out.println(请输入学生的特殊性Y/N);String sp=scanner.nextLine();if (sp.equals(N|n) flag=false;else if (sp.equals(Y|y) flag=true;System.out.println(请输入该学生的语文成绩:);double chinese=scanner.nextDouble();System.out.println(请输入该学生的数学成绩);double math=scanner.nextDouble();System.out.println(请输入该学生的英语成绩:);double english=scanner.nextDouble();System.out.printl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度重点工程土石方工程居间服务费标准范本
- 2025版滕彩离婚协议书附离婚协议签订及履行监督服务
- 2025版涉外法律事务处理及咨询合同下载
- 2025版全国离婚协议书审查与鉴定合同
- 2025版土地拍卖后续服务合同示范文本
- 2025版老旧小区改造工程外包施工合同范本
- 2025年切削钻机租赁及智能化改造服务合同
- 2025年度关键岗位保密及禁止同行业竞争协议
- 2025年度电工电气设备租赁与维护服务合同
- 2025版在线医疗健康服务平台采购与推广合同
- 沈阳地铁入职笔试题目及答案
- 产后耻骨护理
- 杜甫草堂介绍
- 影响购房者决定的心理因素研究
- 汽车托运协议书
- 职业技术学院《质量管理》课程标准
- 湖南省张家界市永定区2024-2025学年九年级下学期毕业学业水平考试模拟(一)语文试题(含答案)
- 烟草物流培训课件
- 部编版小学四年级语文上册教学计划及教学进度表
- 2025年乡村医生考试题库(基础医学知识)历年真题与解析试题卷
- 高速公路笔试试题及答案
评论
0/150
提交评论