-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
58 lines (42 loc) · 1.04 KB
/
Rectangle.java
File metadata and controls
58 lines (42 loc) · 1.04 KB
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
public class Rectangle
{
private int height;
private int width;
/*
default constructor that takes no parameters and creates a rectangle of height 10 and width 5
*/
public Rectangle(){ // constructor that takes no parameters and creates a default 5x10 rectangle
height = 10;
width = 5;
}
/*
Rectangle constructor that takes in two parameters- and creates an object accordingly
*/
public Rectangle(int mHeight,int mWidth){
height = mHeight;
width = mWidth;
}
public int getHeight(){
return height;
}
public void setHeight(int newHeight){
height = newHeight;
}
public void setWidth(int newWidth){
width = newWidth;
}
public int getWidth(){
return width;
}
public int getArea(){
int area = height*width;
return area;
}
public static void main ( String[] args){
Rectangle defRectangle = new Rectangle();
Rectangle customRectangle = new Rectangle(2,2);
System.out.println(defRectangle.getHeight());
System.out.println(defRectangle.getWidth());
System.out.println(defRectangle.getArea());
}
}