-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRectangle.java
88 lines (76 loc) · 1.95 KB
/
Rectangle.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
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @author Bjarne Stroustrup
*/
public class Rectangle {
private double length;
private double width;
private int xCoordinate;
private int yCoordinate;
/**
* Query for the length of the rectangle.
* @return the length
*/
public double getLength ( ) {
return this.length;
}
/**
* Sets the length of the rectangle.
* @param length the length
*/
public void setLength ( double length ) {
this.length = length;
}
/**
* Query for the width of the rectangle.
* @return the width
*/
public double getWidth ( ) {
return this.width;
}
/**
* Sets the width of the rectangle.
* @param width the width
*/
public void setWidth ( double width ) {
this.width = width;
}
/**
* Query for the area of the rectangle.
* @return the area (length * width)
*/
public double getArea ( ) {
return this.length * this.width;
}
/**
* Query for the x coordinate of the rectangle.
* @return the x coordinate
*/
public int getX ( ) {
return this.xCoordinate;
}
/**
* Query for the y coordinate of the rectangle.
* @return the y coordinate
*/
public int getY ( ) {
return this.yCoordinate;
}
/**
* Moves the rectangle to a new position.
* @param x the new x coordinate
* @param y the new y coordinate
*/
public void moveTo ( int x, int y ) {
this.xCoordinate = x;
this.yCoordinate = y;
}
/**
* @return a string representation of the Rectangle
*/
public String toString ( ) {
return "width: " + this.width + ", " +
"length:" + this.length + ", " +
"x coordinate: " + this.xCoordinate + ", " +
"y coordinate: " + this.yCoordinate;
}
}