簡體   English   中英

圓形對象構造函數未定義

[英]circle object constructor not defined

我正在嘗試使類circle擴展Shape類,但不斷從JUnit收到錯誤消息,說未定義構造函數Circle(Point,int),我將如何定義Circle構造函數與公共Circle(Point [] center,int aradius)不同?

import java.awt.Point;

public abstract class Shape {
private String  name;
private Point[] points;
protected Shape(){};
protected Shape(String aName) {
    name = aName;
}

public final String getName() {
    // TODO Implement method
    return name;
}

protected final void setPoints(Point[] thePoints) {
    points = thePoints;
}

public final Point[] getPoints() {
    // TODO Implement method
    return points;
}

public abstract double getPerimeter();

public static double getDistance(Point one, Point two) {
    double x = one.getX();
    double y = one.getY();
    double x2 = two.getX();
    double y2 = two.getY();
    double x3 = x - x2;
    double y3 = y - y2;
    double ypow = Math.pow(y3, 2);
    double xpow = Math.pow(x3, 2);
    double added = xpow + ypow;
    double distance = Math.sqrt(added);
    return distance;
}
}

Circle.java

import java.awt.Point;

public class Circle extends Shape{

private double radius;

public Circle(Point[] center, int aradius) {

    if(radius < 0){
        radius = 0;
    }
    else{
    radius = aradius;
    }
    this.setPoints(center);
}

@Override
public double getPerimeter() {
    double perim = 2 * Math.PI * radius;
    return perim;
}
  public double getRadius(){
  return radius;
  }

}

只需將其傳遞給單個Point ,而不是數組即可。

public Circle(Point center, int aradius)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM