Add lab6
This commit is contained in:
58
lab/lab6/Question1/Shape.java
Normal file
58
lab/lab6/Question1/Shape.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user