-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangletest.java
61 lines (55 loc) · 1.39 KB
/
Rectangletest.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
class Rectangle2{
private double length;
private double breadth;
public Rectangle2(){
length=1;
breadth=1;
}
public Rectangle2(double l,double b){
setLength(l);
setBreadth(b);
}
public Rectangle2(double s){
length=breadth=s;
}
public void setBreadth(double breadth) {
this.breadth = breadth;
}
public void setLength(double length) {
this.length = length;
}
public double getBreadth()
{
return breadth;
}
public double getLength()
{
return length;
}
public double area(){
return length*breadth;
}
public double perimeter(){
return 2*(length+breadth);
}
boolean isSquare(){
if(length==breadth){
return true;
}
else{
return false;
}
}
}
public class Rectangletest {
public static void main(String[] args) {
Rectangle2 r1 = new Rectangle2(10,20);
System.out.println("Area of rectangle is " + r1.area());
System.out.println("Perimeter of rectangle is " + r1.perimeter());
System.out.println("Is rectangle square? " + r1.isSquare());
// r1.setBreadth(2);
// r1.setLength(3);
// System.out.println(r1.getLength());
// System.out.println(r1.getBreadth());
}
}