-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ04002.java
More file actions
77 lines (60 loc) · 1.76 KB
/
J04002.java
File metadata and controls
77 lines (60 loc) · 1.76 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//src/J04002.java
import java.util.*;
public class J04002 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Rectange r = new Rectange(sc.nextInt(), sc.nextInt(), sc.next());
System.out.println(r);
}
}
//src/Rectange.java
class Rectange {
private double width;
private double height;
private static String color;
public Rectange() {
this.width = 1;
this.height = 1;
}
public Rectange(double width, double height, String color) {
this.width = width;
this.height = height;
this.color = color;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public static String getColor() {
return color;
}
public static void setColor(String color) {
Rectange.color = color;
}
public double findArea() {
return this.height * this.width;
}
public double findPerimeter() {
return 2*this.height + 2*this.width;
}
public String toString() {
if (this.height <=0 || this.width <=0) {
return "INVALID";
}
StringBuilder sb = new StringBuilder("");
String res = this.color.trim();
sb.append(Character.toUpperCase(res.charAt(0)));
for (int i =1;i<res.length();i++) {
sb.append(Character.toLowerCase(res.charAt(i)));
}
return (int)this.findPerimeter() + " " + (int)this.findArea() + " " + sb.toString();
}
}