-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
132 lines (106 loc) · 2.63 KB
/
Solution.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int menu, sisi, alas, tinggi, jari2;
menu = input.nextInt();
if (menu == 1) {
sisi = input.nextInt();
Kotak kotak = new Kotak(sisi, sisi);
System.out.println(kotak.getArea());
}
else if (menu == 2) {
alas = input.nextInt();
tinggi = input.nextInt();
Segitiga segitiga = new Segitiga(alas, tinggi);
System.out.println(segitiga.getArea());
}
else if (menu == 3) {
jari2 = input.nextInt();
Lingkaran lingkaran = new Lingkaran(jari2);
System.out.println((double)lingkaran.getArea());
}
else {
System.out.println("Input yang anda masukan tidak sesuai");
}
}
}
class Kotak {
private double width, length;
Kotak(){
this.width = 0;
this.length = 0;
}
Kotak(double width, double length){
this.width = width;
this.length = length;
}
public double getWidth(){
return width;
}
public double getLength(){
return length;
}
public void setWidth(double width){
this.width = width;
}
public void setLength(double length){
this.length = length;
}
public int getArea(){
return (int) (width * length);
}
}
class Lingkaran {
private double radius;
Lingkaran() {
this.radius = 0;
}
Lingkaran(double radius) {
this.radius = radius;
}
public double getRadius() {
return this.radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public int getArea() {
double area;
int mod = (int) (radius % 7);
if (mod == 0 && radius >= 7) {
area = 22/7 * radius * radius;
}
else {
area = 3.14 * radius * radius;
}
return (int) area;
}
}
class Segitiga {
private double alas;
private double tinggi;
Segitiga(){
this.alas = 0;
this.tinggi = 0;
}
Segitiga(double alas, double tinggi){
this.alas = alas;
this.tinggi = tinggi;
}
public double getAlas() {
return alas;
}
public void setAlas(double alas) {
this.alas = alas;
}
public double getTinggi() {
return tinggi;
}
public void setTinggi(double tinggi) {
this.tinggi = tinggi;
}
public int getArea(){
return (int) ((this.alas * this.tinggi) / 2);
}
}