저는 Dr. Java를 사용하여 사각형 클래스를 만들려고합니다. 사각형 클래스에서 대부분의 코드를 가져 왔지만 엉망이되었습니다. 저는 현재 Java에 관해서 초보자이므로 지금 당장 실망합니다. 내 정사각형 교정 방법에 대한 수정이나 조언이 있으면 알려주십시오. 또한 여기 사각형 클래스를 만드는 데 많은 도움이 필요합니다.
package graphics2;
/**
* A class that represents a square with given origin, width, and height.
*/
public class Square extends Graphics {
// The private width and height of this square.
private double width = 0;
private double height = 0;
/**
* Constructs a square with given origin, width, and height.
*/
public Square(Point origin, double side) {
super(origin, side, side);
setOrigin(new Point(0, 0));
width = height = side;
}
/**
* Constructs a square with given width and height at origin (0, 0).
*/
public Square(double side) {
setOrigin(new Point(0, 0));
width = height = side;
}
/**
* Returns the square's side of this square.
*/
public double getSide() {return width;}
/**
* Returns the width coordinate of this square.
*/
public double getWidth() {return width; }
/**
* Returns the height coordinate of this square.
*/
public double getHeight() {return height; }
/**
* Returns the area of this square.
*/
public double area() {
return width * height;
}
}
감사
내가 받고있어 오류입니다 :1 error found:
File: C:\Users\GreatOne\Desktop\06Labs-\graphics2\Square.java [line: 15]
Error: The constructor graphics2.Graphics(graphics2.Point, double, double) is undefined
변수를 선언하지 않았으므로 변수를 어떻게 사용합니까? 또한'Graphics'에서 파생 하시겠습니까? 네모는 정말 그래픽 컨텍스트인가? – Zong