我正在尝试使用 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