-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRectangle.java
More file actions
66 lines (55 loc) · 1.25 KB
/
Copy pathRectangle.java
File metadata and controls
66 lines (55 loc) · 1.25 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
59
60
61
62
63
public class Rectangle
{
private float length;
private float width;
public Rectangle()
{
length=1;
width=1;
}
public Rectangle(float length,float width)
{
setLength(length);
setWidth(width);
/* this.length=length;
this.width=width; */
}
public void setLength(float length)
{
if(length>=0.0 && length <=20.0)
this.length=length;
else
this.length=1;
}
public void setWidth(float width)
{
if(width>=0.0 && width <=20.0)
this.width=width;
else
this.width=1;
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
public double area()
{
return length*width;
}
public double perimeter()
{
return 2*(length+width);
}
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
Rectangle rect2 = new Rectangle(40.0f,30.0f);
System.out.println("Area of Rectangle(default): "+rect.area());
System.out.println("Area of Rectangle: "+rect2.area());
System.out.println("Perimeter of Rectangle: "+rect2.perimeter());
}
}