- 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
您可能关注的文档
- 列车时刻表20110518.doc
- 刘拥-13专升本-vc++应用开发进度表.doc
- 创建主控文档和子文档.doc
- 初3信息技术月考题(附答案).doc
- 初三图形旋转.doc
- 初三数学,用一元二次方程解决实际问题.doc
- 初三复习题纲2011.doc
- 初三第10讲.doc
- 初三第三节课《程序的分支结构及条件语句IF》.doc
- 初三物理期末考试试卷质量分析.doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
原创力文档

文档评论(0)