-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_rectangle.java
81 lines (74 loc) · 1.54 KB
/
class_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
/*
Input -> 1
Output -> 5
2
7
3
Rectangle[x=5,y=2,width=7,height=3]
13
27
2
42
Rectangle[x=13,y=27,width=2,height=42]
2
3
4
5
Rectangle[x=2,y=3,width=4,height=5]
*/
import java.util.Scanner;
class Rectangle
{
int x,y,width,height;
Rectangle(int a,int b,int c,int d)
{
this.x=a;
this.y=b;
this.width=c;
this.height=d;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public String toString()
{
return ("Rectangle[x="+x+",y="+y+",width="+width+",height="+height+"]");
}
}
class Main
{
public static void main(String[] args)
{
Rectangle r1=new Rectangle(5,2,7,3);
Rectangle r2=new Rectangle(13,27,2,42);
Rectangle r3=new Rectangle(2,3,4,5);
System.out.println(r1.getX());
System.out.println(r1.getY());
System.out.println(r1.getWidth());
System.out.println(r1.getHeight());
System.out.println(r1.toString());
System.out.println(r2.getX());
System.out.println(r2.getY());
System.out.println(r2.getWidth());
System.out.println(r2.getHeight());
System.out.println(r2.toString());
System.out.println(r3.getX());
System.out.println(r3.getY());
System.out.println(r3.getWidth());
System.out.println(r3.getHeight());
System.out.println(r3.toString());
}
}