实验一 面向对象的开发方法实验指导

  • 格式:docx
  • 大小:348.19 KB
  • 文档页数:5

实验一面向对象的开发方法
一、实验目的
掌握面向对象程序开发方法,含类的定义和使用,封装、继承、多态。

理解封装思想,掌握类、包、类的层次等基本概念,掌握类、接口等的语法实现。

掌握继承的概念,掌握类成员的可见性,函数的覆盖。

掌握多态的思想,能够熟练实现多态。

二、实验要求
通过现实中的一个应用场景用Java实现一个简单控制台应用程序,具体包括:1)封装与信息隐藏,行为与实现的分离; 2)类与子类,继承(支配,动态派生); 3)多态性(子类型多态和继承),类的层次按实验内容及步骤完成操作,完成实验报告,所有实验环节均由每位学生独立完成,严禁抄袭他人实验结果。

三、实验环境
主流PC机一套,windows操作系统eclipse开发平台。

四、实验内容
1、应用场景描述:
You have just been hired by a small company called Baby-Sitters, Inc.,
which provides baby sitters to families. The company wants to develop a small calculator which can calculate the pay for a baby-sitter.
To make it more simple, assumes that the starting time for the baby-sitter is somewhere between 6 PM and 11 Pm; and that the ending time is somewhere between 9 PM and 4 AM.
The only variables that provide "input" to the computation will be 4 numbers: the starting time expressed in hours and minutes and the ending time expressed in hours and minutes. For example, if the baby sitter works from 7:45 PM until 1:12 AM, then the four variables might be set something like the following.
... int startHour= 7;
... int startMinute = 45;
... int endHour = 1;
... int endMinute = 12;
The result of your program is to provide the amount of money to be paid to the baby-sitter. The pay sale is: $3.40 per hour for 6 PM until midnight;
$3.90 an hour after midnight. Decide on whether to use constants or variables
for these two pay scales.
五、原理知识
面向对象方法(Object Oriented Method)是一种把面向对象的思想应用于软件开发法过程,指导开发活动的系统方法,是建立在“对象”概念基础上的方法学。

面向对象的思想
问题域是由对象构成的,每个对象拥有各自的属性和方法,属性用于描述对象的物理特征,而方法用于描述对象的行为,对象是属性和行为的统一体。

图1:类的实例化
图2:消息、接口、对象
图3:面向对象的基本含义
图4:面向对象的优缺点
图5:面向对象的特点
六、实验报告要求
填写实验报告,包括姓名、学号、专业班级和实验名称等项,在报告中详细记录实验结果及遇到的问题和解决办法。