-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
48 lines (40 loc) · 981 Bytes
/
Copy pathShape.java
File metadata and controls
48 lines (40 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package models;
public abstract class Shape implements Comparable<Shape> {
protected double height;
protected double baseArea;
protected double volume;
abstract void calculateBaseArea();
abstract void calculateVolume();
/**
* Compares shapes based on their height. Returns the difference between their
* heights. this - comparedTo shape.
*
* @param shape
* @return the difference between the two shapes heights.
*/
@Override
public int compareTo(Shape shape) {
return (int) Math.ceil(height - shape.getHeight());
}
/**
* @return the height
*/
public double getHeight() {
return height;
}
/**
* @return the baseArea
*/
public double getBaseArea() {
return baseArea;
}
/**
* @return the volume
*/
public double getVolume() {
return volume;
}
public String toString() {
return String.format("Height: %-16.3fbaseArea: %-16.3fVolume: %-16.3f", height, baseArea, volume);
}
}