编写一个完整的Java Application程序,包含接口shapeArea,类Rectangle.Test.要求如下:

来源:百度知道 编辑:UC知道 时间:2024/05/23 19:54:02
1.接口shapeArea:
a.接口方法.
double getArea():求一个形状的面积;
double getPerimeter():求一个形状的周长.
2.类Rectangle:实现shapeArea接口,并有以下属性和方法.
a.属性.
width:double型,表示长方形的宽度.
height:double型,表示长方形的长度.
b.方法.
Rectangle(double w,double h):构造函数.
toString0:输出矩形的描述信息,如:”width=1.0,heigth=2.0,perimeter=6.0,area=2.0"
3.Test类作为主类要完成测试功能.
a.生成Rectangle对象.
b.调用对象的toString方法,输出对象的描述信息.
程序怎么这么复杂啊,这是我们的期末考试题目,老师应该是不会出这么难的题目的,麻烦再想想,.
呵呵,不会吧,我们学的没这么长的程序啊/
我觉得程序段这里可以修改以下,简短一点,你先看看,不晓得行不行 "System.out.print("width= ");
System.out.print(width);
System.out.print(",");
System.out.print("height= ");
System.out.print(height);
System.out.print(",");
System.out.print("perimeter= ");
System.out.print(getPerimeter());
System.out.print(",");
System.out.print("area= ");
System.out.print(getArea());

shapeArea.java
----------------------------------------
public interface shapeArea{
public double getArea();
public double getPerimeter();
}
----------------------------------------

Rectangle.java
----------------------------------------

import java.lang.*;
class Rectangle implements shapeArea{
private double width;
private double height;
public Rectangle(double w,double h){
width = w;
height = h;
}
public double getArea(){
return width * height;
}
public double getPerimeter(){
return width*2 + height*2;
}
public void toString0(){
//”width=1.0,heigth=2.0,perimeter=6.0,area=2.0"
System.out.print("width= ");
System.out.print(width);
System.out.print(",");
System.out.print("height= ");
Sys