实验4 类与对象.docVIP

  • 24
  • 0
  • 约7.31千字
  • 约 10页
  • 2017-05-12 发布于河南
  • 举报
实验4 类与对象

实验4 类与对象 一、实验目的 通过编程和上机实验理解 Java 语言是如何体现面向对象编程基本思想,了解类的封装方法,以及如何创建类和对象,了解成员变量和成员修饰方法的特性,掌握 OOP 方式进行程序设计的方法。 二、实验要求 1. 编写创建对象和使用对象的方法的程序。 2. 编写显示当前日期和时间的程序。 3. 编写不同成员变量、成员方法修饰方法的程序。 三、实验内容 (一) 类、对象的使用 1.编写Java代码实现一个计数器类Computer,要求: (1)包含属性counterValue用来保存计数器的当前值; (2)成员方法increment() 计数器加一,decrement() 计数器减一,方法reset()计数器清零。 2.编程实现矩形类,要求: (1)包含属性长与宽; (2)类中有成员方法计算矩形周长和面积的方法。 3 .编程完成梯形类() (1)public class Tixing { double upper,lower,high; } (2)public class Tixing { double upper,lower,high; double getArea(){ return (upper+lower)*high/2; } } (3)public class Tixing { double upper,lower,high; double getArea(){ return (upper+lower)*high/2; } public double getUpper() { return upper; } public void setUpper(double upper) { this.upper = upper; } public double getLower() { return lower; } public void setLower(double lower) { this.lower = lower; } public double getHigh() { return high; } public void setHigh(double high) { this.high = high; } } (4)public class Tixing { double upper,lower,high; public Tixing() { } public Tixing(double upper, double lower, double high) { this.upper = upper; this.lower = lower; this.high = high; } double getArea(){ return (upper+lower)*high/2; } public double getUpper() { return upper; } public void setUpper(double upper) { this.upper = upper; } public double getLower() { return lower; } public void setLower(double lower) { this.lower = lower; } public double getHigh() { return high; } public void setHigh(double high) { this.high = high; } } (5) public class Tixing { double upper,lower,high; public Tixing() { } public Tixing(double upper, double lower, double high) { this.upper = upper; this.lower = lower; this.high = high; } double getArea(){ return (upper+lower)*high/2; } public double getUpper() { return upper; } public void setUpper(double upper) { this.upper = upper; } public double getLower() { return lower; } public void setLower(dou

文档评论(0)

1亿VIP精品文档

相关文档