实验目的:
通过编程和上机实验,掌握类和构造方法的定义及创建对象的方法,掌握类的封装及继承原则,正确使用重载和覆盖等多态概念设计可复用方法,熟悉包、接口的使用方法,掌握面向对象的程序设计方法。
实验内容:
1、编写 MyDate 类,完善上次实验中的人员信息录入,实现日期合法性判断,包括大小月和闰年。
代码见实验三
2、定义接口 Shape 及其抽象方法 getArea()和 getPerimeter()用于计算图形和面积和周长。定义类 Rectangle(矩形)、类 Circle(圆形)、类 Triangle(三角形),
要求这些类继承点类 Coordinates()并实现接口的抽象方法。
提示:
class Coordinates
{
long x;
long y;
Coordinate(long x, long y)
{
this.x=x;
this.y=y;
}
}
(1)源代码
package experiment;
import java.util.*;
interface Shape
{
public abstract double getArea();
public abstract double getPerimeter();
}
class Coordinate
{
long x;
long y;
Coordinate(long x,long y)
{
this.x=x;
this.y=y;
}
Coordinate()
{
this.x=0;
this.y=0;
}
}
class Rectangle extends Coordinate implements Shape
{
private double length;
private double width;
private Coordinate upleft;
Rectangle()
{
this.length=length;
this.width=width;
this.upleft=new Coordinate();
}
Rectangle(double length,double width,long x,long y)
{
this.length=length;
this.width=width;
this.upleft=n

该实验旨在通过编程实践,帮助学生掌握JAVA中类的定义、构造方法、封装、继承以及多态的概念。实验内容包括创建MyDate类进行日期合法性检查,以及设计Shape接口和实现该接口的Rectangle、Circle、Triangle类,实现图形的面积和周长计算。
最低0.47元/天 解锁文章
1335

被折叠的 条评论
为什么被折叠?



