




免费预览已结束,剩余2页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、实验目的及内容目的:掌握和巩固Java面向对象程序设计的概念、方法。内容:1. 设计一个Java程序,该程序运行后,说明:一个类的所有对象共享同一个类成员变量;一个类的多个对象拥有各自的实例成员变量。2. 编写一个表示人的类Person,该类满足以下要求:l 有两个private成员变量:name(名字)、age(年龄);在Person类外访问这两个成员变量均通过接口器函数(getXXX,setXXX)。l 该类具有一个有两个参数的构造函数,这两个参数分别用来初始化name和age成员变量。l 该类包含一个方法public boolean older(Person r),用于比较当前对象年纪是否比参数r的年纪大,若是,则返回true,否则,返回false。编写另外一个类:TestPerson,该类包含下面函数:public static void sortPerson(Person personList),在该函数中利用Person类的older方法实现对数组personList按年龄从小到大排序。main函数位于该类中。在main函数中(1) 创建Person类的10个对象,并保存到一个数组中,创建10个对象时,每个对象的年龄为0100的一个随机数(用Math.random()函数得到)。(2) 输出这个数组中每个对象的名字、年龄。(3) 调用sortPerson方法,对这个数组中的10个Person对象按年龄排序。(4) 输出排序后数组中每个对象的名字、年龄。二、要求1. 给出上述程序的中涉及到的类的类图(可用visio画)、解决上述问题的思路、代码和测试结果。1.设计一个Java程序,该程序运行后,说明:一个类的所有对象共享同一个类成员变量;一个类的多个对象拥有各自的实例成员变量。设计思路:要实现一个类的所有对象共享同一个类成员变量;一个类的多个对象拥有各自的实例成员变量。我创建了一个Number类,并创建了两个对象number1和number2,该类有一个类成员函数static int numberofsum(int a, int b)来求和,一个类成员变量countnumber来统计对象的个数,还有实例成员变量num,通过两个对象求和以及统计对象个数,说明了一个类的所有对象共享同一个类成员变量,两个对象都有自己的num值说明了一个类的多个对象拥有各自的实例成员变量。类图:程序代码:/package number; public class Number public static void main(String args) System.out.println(Create two numbers!); Number number1 = new Number(5); System.out.println(After create the first number,countnumber is + number1.countnumbers); Number number2 = new Number(10); System.out.println(After create the second number,countnumber is + number2.countnumbers); System.out.println(The two numbers is + number1.num + and + number2.num); System.out.println(The sum of two numbers is + numberofsum(number1.num, number2.num); static int countnumbers = 0; int num; Number(int a) num = a; countnumbers+; static int numberofsum(int a, int b) int sum = a + b; return sum; 测试结果:2.编写一个表示人的类Person,以及另外一个类:TestPerson。具体要求见实验内容。 设计思路:定义两个类Person和TestPerson,TestPerson类中有public static void sortPerson(Person personList)来对创建的十个对象进行年龄大小排序。类图:程序代码:/package testperson; import java.util.Scanner;public class TestPerson public static void main(String args) final int number = 10; Scanner input = new Scanner(System.in); Person personArray = new Personnumber; for (int i = 0; i personArray.length; i+) System.out.print(Please enter the name of person + (i + 1) + :); String personName = input.next(); int personAge = (int) (Math.random() * 100); personArrayi = new Person(personAge, personName); System.out.println(The + (i + 1) + persons name is + personArrayi.getName() + and the age is + personArrayi.getAge(); sortPerson(personArray); public static void sortPerson(Person personList) Person t; for (int i = 0; i personList.length - 1; i+) for (int j = i + 1; j personList.length; j+) if (personListi.older(personListj) t = personListi; personListi = personListj; personListj = t; System.out.println(The age from young to old order is:); for (int k = 0; k r.age) return true; else return false; 测试结果:protection design of tall buildings GB50045-95 the construction interior trim design fire protection standard GB50222-95 6, building curtain wall design code for lightning protection lightning protection standard building GB50057-94 7, building curtain wall technical standards for lighting architectural lighting design standard GB/T50033-2001 optical properties of glass curtain wall GB/ T18091-2000 8, physical inspection and technical standards of architectural curtain wall construction performance testing method for in-plane deformation of curtain wall GB/T18250-2000 classification GB/T15225-94 wind pressure of building curtain wall building curtain wall physical properties deformation performance test method GB/T15227-94 curtain GB/T15226-94 curtain air permeability test methods rainwater seepage performance test methods GB/T15228-94 9, Windows testing technical standards of architectural curtain wall House Windows airtight, watertight and wind resistance performance test method JG/T211-2007 House Windows
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 学校茶水间管理制度
- 学校饮水水管理制度
- 学生洗澡室管理制度
- 宁波港门卫管理制度
- 安全生产周管理制度
- 安装加工件管理制度
- 实训室教师管理制度
- 宠物店公司管理制度
- 客房消毒间管理制度
- 室外弱电井管理制度
- 国家开放大学2025年《创业基础》形考任务3答案
- 江岸区2023-2024学年下学期期末七年级数学试卷(含答案)
- 来料质量异常反馈单
- n系列蒸汽型溴化锂吸收式冷水机组f.ju.1
- 会展策划与管理高水平专业群建设项目建设方案
- 2021-2022学年江苏省扬州市高一下学期期末地理试题
- 司炉岗位应急处置卡(燃气)参考
- 最新四川省教师资格认定体检表
- 串并联电路电压表电流表(课堂PPT)
- XXX县第三次国土调查技术报告
- 肝硬化基本知识ppt课件
评论
0/150
提交评论