forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise13_10.java
76 lines (66 loc) · 2.81 KB
/
Exercise13_10.java
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ch_13.exercise13_10;
//_________________________ UML DIAGRAM ____________________________*
/* *
* GeometricObject *
*------------------------------------------------------------------*
* -color: String *
* -filled: boolean *
* -dateCreated : java.util.Date *
* *
*------------------------------------------------------------------*
* #GeometricObject() *
* #GeometricObject(color:String,filled:boolean) *
* *
* *
* +getColor(): String *
* +setColor(color: String): void *
* +isFilled(): boolean *
* +setFilled(filled: boolean): void *
* +getDateCreated(): java.util.Date *
* *
* +toString(): String *
* /+getArea()/: double/ *
* /+getPerimeter(): double/ *
* _________________________________________________________________| */
/* ^
^
^
^
/*_________________UML Diagram__________________*
*______________________________________________*
* Rectangle *
*______________________________________________*
* *
* width: double *
* *
* height: double *
* * _____________________________________
* Rectangle() * * <<interface>> *
* * * java.lang.Comparable<Rectangle> *
* Rectangle(newWidth:double, newHeight:Double)* >>>>>>>>>>>>>>>>>>>>>>*___________________________________*
* * * +compareTo(obj:Rectangle):int *
* getArea(): double * *___________________________________*
* getPerimeter(): double *
* *
* +toString(): String *
* +compareTo():int *
* +equals(): boolean *
* _____________________________________________*
*/
/* ******************************************* */
/**
* 13.10. (Enable Rectangle comparable) Rewrite the Rectangle class in
* Listing 13.3 to extend GeometricObject and implement the Comparable
* interface. Override the equals method in the Object class. Two Rectangle
* objects are equal if their areas are the same. Draw the UML diagram that
* involves Rectangle, GeometricObject, and Comparable.
*/
public class Exercise13_10 {
public static void main(String[] args) {
Rectangle rectangle1 = new Rectangle(4, 7, "Yellow", true);
Rectangle rectangle2 = new Rectangle(4, 7, "Blue", false);
System.out.println("\nRectangle 1:\n " + rectangle1.toString()
+ "\n\nand\n" + "\nRectangle 2: \n" + rectangle2.toString());
System.out.println("\nAre they equal? " + rectangle1.equals(rectangle2));
}
}