file-type

JAVA长方体类实现与绘制方法实验报告

版权申诉

RAR文件

5星 · 超过95%的资源 | 15KB | 更新于2024-11-23 | 58 浏览量 | 1 下载量 举报 收藏
download 限时特惠:#14.90
知识点详细说明: 1. 面向对象编程基础: 面向对象编程(Object-Oriented Programming, OOP)是一种编程范式,它使用“对象”来设计软件。面向对象的程序设计能够将数据(属性)和行为(方法)封装在对象中。JAVA是一种典型的面向对象的编程语言。 2. 类与对象的概念: 在面向对象编程中,类是创建对象的模板,是对象的抽象描述,它定义了对象的状态和行为。对象是类的实例,是类的具体表现形式。在本实验中,Cuboid类用于描述长方体对象。 3. 私有成员变量: 私有成员变量是一种面向对象编程中的访问控制修饰符,它表示成员变量只能在类的内部被访问。在Cuboid类中,length(长)、width(宽)和height(高)被设置为私有变量,以确保它们的状态只能通过类提供的方法进行修改和访问。 4. 构造方法: 构造方法是一种特殊的方法,用于在创建对象时初始化对象的状态。本实验要求提供两种构造方法:一种是空构造方法,另一种是能初始化所有成员变量的构造方法。 5. setter和getter方法: setter和getter方法用于设置(set)和获取(get)对象的属性值。这些方法通常用于提供对私有成员变量的安全访问。setter方法在设置值时需要进行合法性验证,以确保数据的正确性和完整性。 6. 方法功能实现: - 计算表面积getArea():计算长方体表面积的公式为2*(length*width + width*height + height*length)。 - 计算体积getCubage():计算长方体体积的公式为length*width*height。 - 判断是否正方体isCube():如果长、宽和高相等,则为正方体。 - 输出该长方体的长宽高printCuboid():打印长方体对象的长、宽、高属性值。 - 绘制该长方体drawing():绘制长方体通常涉及到图形用户界面(GUI)编程,本实验中仅提供绘制提示信息。 7. 测试案例: 在面向对象程序设计中,测试案例用于验证对象的行为是否符合预期。本实验报告中包含两个测试案例: - 测试一利用空构造方法创建对象,设置长方体属性值,验证属性值设置是否正确,并通过输出和绘制方法来检查长方体的状态。 - 测试二使用带有参数的构造方法创建对象,修改对象属性,然后计算和验证长方体的表面积和体积是否正确。 8. JAVA文档说明: JAVA.doc文件可能包含了上述实验的完整报告和代码实现。该文件是实验报告的载体,详细描述了实验的目标、方法、实现步骤以及测试结果。 9. JAVA环境搭建与运行: 要运行JAVA程序,需要安装JAVA开发工具包(JDK)并配置相应的环境变量。实验中的程序可以在集成开发环境(IDE)如IntelliJ IDEA、Eclipse中编写和运行,也可以通过命令行工具编译和执行。 通过上述知识点的介绍,可以看出本实验报告不仅仅是对一个具体的编程任务的描述,更是一个面向对象程序设计方法论的学习和实践过程,涵盖了从类的定义、对象的创建到方法实现和测试的全方位内容。这对于学习JAVA编程语言和面向对象编程理念具有重要意义。

相关推荐

filetype
Write a class called Person with the following attributes: title (Mr., Mrs., Ms., etc.) first name last name nickname age in years sex (boolean - true/false to indicated either male or female) Write a constructor that takes no parameters and performs no initializations. Write a constructor that takes a parameter for each of the attributes listed above and sets them within the objects by calling the setter methods listed below. The Person class should have a setter method and a getter method with public access for each attribute. In the setter methods, get rid of any leading or trailing spaces (String trim() method). For a Person with the following attributes: title = "Mr." first name = "Michael" last name = "Zheng" nickname = "Mike" age = 22 sex = true (true is male, false is female) The Person class should have the following public access methods that return Strings as follows: standardName() concatenation of the first and last names (i.e., "Michael Zheng") formalName() concatenation of the title, first name, lastname (i.e., "Mr. Michael Zheng") casualName() return the nickname if it is not null, otherwise return the first name (i.e., "Mike") Be realistic when generating names. If a particular attribute does not exist for a given person, don't try to concatenate it. If necessary, add appropriate spacing and punctuation, but do not leave any leading or trailing spaces in the String that is returned. MakePerson Write a class called MakePerson with a main() method that instantiates 2 Person objects. Initialize the attributes of one of the Person objects by supplying parameters to it's constructor. Instantiate the other Person object with the default constructor (that does not accept any parameters), then set it's attributes via the appropriate setter methods. For each of the Person objects, execute and print (System.out.println()) the results of all of the getter methods and of the standardName(), formalName(), and casualName() methods.
Dyingalive
  • 粉丝: 110
上传资源 快速赚钱