Files
oop/lab/lab6/Question1/Shape.java
2022-03-27 18:46:18 +08:00

59 lines
1.0 KiB
Java

/**
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007) Date: 2022/03/27
* Description: This is the Shape class.
*/
public class Shape {
private double x;
private double y;
/**
* Constructor
*
* @param x the position of the center point of the shape
* @param y the position of the center point of the shape
*/
public Shape(double x, double y) {
this.x = x;
this.y = y;
}
/**
* Getter of x
*
* @return the position of the center point of the shape
*/
public double getX() {
return x;
}
/**
* Getter of y
*
* @return the position of the center point of the shape
*/
public double getY() {
return y;
}
/**
* The are of the shape
*
* @return the area of the shape
*/
public double area() {
System.out.println("An unknown shape has an unknown area!");
return -1.0;
}
/**
* Test
*/
public static void testShape() {
Shape s = new Shape(1.0, 2.0);
System.out.println(s.getX() == 1.0);
System.out.println(s.getY() == 2.0);
System.out.println(s.area() == -1.0);
}
}