-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.java
69 lines (58 loc) · 1.39 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
/**
* Write a description of class Rectangle here.
*
* @author (your name)
* @version (a version number or a date)
*/
import gpdraw.*;
public class Rectangle{
// instance variables - replace the example below with your own
private double myX;
private double myY;
private double myWidth;
private double myHeight;
private DrawingTool pen;
private SketchPad paper;
/**
* Constructor for objects of class Rectangle
*/
public Rectangle()
{
}
public Rectangle(double x, double y, double width, double height)
{
myX = x;
myY = y;
myWidth = x += width;
myHeight = y += height;
pen = new DrawingTool();
}
public double getPerimeter()
{
double perimeter = myWidth + myWidth + myHeight + myHeight;
return perimeter;
}
public double getArea()
{
double area = myWidth * myHeight;
return area;
}
public void draw()
{
pen.up();
pen.move(myX, myY);
pen.down();
pen.drawRect(myWidth, myHeight);
/*
pen = new DrawingTool();
pen.move(myX, myY);
pen.forward(myWidth);
pen.turnLeft(90);
pen.forward(myHeight);
pen.turnLeft(90);
pen.forward(myWidth);
pen.turnLeft(90);
pen.forward(myHeight);
*/
}
}