具体要求如下:
⑴接口ShapeArea:
①接口方法
double getArea():求一个形状的面积
double getPerimeter ():求一个形状的周长
⑵类Circle:
实现ShapeArea接口,并有以下属性和方法:
③ 属性
radius: double类型,表示圆的半径
④ 方法
Circle(double r):构造函数
toString()方法 :输出圆的描述信息,如“radius=1.0, perimeter=6.28, area=3.14”
⑶Test类作为主类要完成测试功能
生成Circle对象
调用对象的toString方法,输出对象的描述信息
编写一个完整的Java Application 程序。包含接口ShapeArea,类Circle...
\/\/把下面的代码复制到同一个文件中,把名字改为:Test.java 然后编译,运行就可以了~interface ShapeArea{ double getArea();double getPerimeter();} class Rectangle implements ShapeArea{ double width;double height;public Rectangle(double w, double h){ this.width=w;this.height=h;} public...
编写一个完整的Java Application 程序.包含类Circle,Cylinder,ShapeTest...
public ShapeTest() { Circle circle = new Circle(10.0d);System.out.println("面积:"+circle.area()+"周长:"+circle.perimeter());Cylinder cylinder = new Cylinder(10.0d, 10.0d);System.out.println("表面积:"+cylinder.area()+"体积:"+cylinder.volume());} } ...
完整Application编程 包含Shape Circle类及Test
import java.awt.*;abstract class Shape \/\/抽象类定义(3分){ public abstract double getPerimeter();public abstract double getArea();} public class Test { public static void main(String args[]) \/\/main()方法定义(2分){ MyCircle c=new MyCircle(1.0);System.out.println(c.to...
java设计图形(Shape)类及其子类(Circle、Rectangle)
public double area(){ return 0.0;} } Circle类:public class Circle extends Shape{ private int r;public Circle() { } public Circle(Point center,int r) { super.location=center;this.r = r;} public double area() { return Math.PI*r*r ;} } Rectangle类:public class Rectan...
Java 编写一个矩形类实现shape接口。 编写一个圆类实现shape接口。 编...
图形接口 \/ public interface shape { \/\/ 得到面积 public double getArea (int radiusOrLength, int width);\/\/ 得到周长 public double getPerimeter(int radiusOrLength, int width);} \/ author Administrator 圆形 \/ public class Circle implements shape{ \/\/ π定义 private final static double ...
...一个Shpe接口和它的两个实现类Square和circle,要求如下: (1)Sh...
\/\/ 接口类public interface Shpe{ public double area(double num );}\/\/实现类-正方形 public class Square implements Shpe{ @Override public double area( double num ){ return num * num; }}\/\/实现类-圆 public class Circle implements Shpe{ @Override public double ...
1.编写一个Java程序,在程序中定义一个抽象类Shape,里面有一个求面积...
public class Rectangle extends Shape{double a,b;Rectangle(double a,double b){this.a = a;this.b = b;}@Overridedouble GetArea() {return a*b;}}Test1.java类 import java.util.Scanner;public class Test1{public static void main(String[] args){Scanner sca = new Scanner(System.in...
...形状类(Shape)、圆类(Circle)、矩形类(Rectangle),要求:
float Circle::getArea() { return 3.1416*radius*radius;} int main (){ Shape *s[2];int i;s[0] = new Rectangle (4,3);s[1] = new Circle (5);for (i=0;i<2;i++) cout << "area[" <<i<< "]=" << s[i]->getArea() << endl;return 0;} 输出:area[0]=12 ...
...从Shape类扩展出矩形Rectangle类和圆类Circle,这两个
public class MyTest {\/\/测试类 public static void main(String[] args) { Rectangle rec = new Rectangle(4.7, 5.1);double recArea = rec.area();System.out.println("矩形的长5.1,宽4.7,面积:" + recArea);Circle cir = new Circle(6.4);double cirArea = cir.area();Syste...
JAVA:编写求解几何图形(如三角形,矩型,圆,多边型)的周长、面积的应用程...
定义一个接口:\/** * 接口类 *\/public interface Shape { \/** * 求周长 * * @return *\/ double perimeter(); \/** * 求面积 * * @return *\/ double area();}计算三角形面机:\/** * 三角形 *\/public class Triangle implements Shape { ...