Adam Nur Wicaksono
230402071
2A3
UTS PBO (Pemrograman Berorientasi Objek)
Class persamaan1
1. Persamaan1 int a;
public class persamaan1 { int b;
int a; int c;
double y;
int b;
int c; Input_data()
double y; Proses()
private void input_data() throws IOException {
DataInputStream input = new DataInputStream(System.in);
System.out.print("a = ");
P
a = Integer.parseInt(input.readLine());
System.out.print("b = ");
b = Integer.parseInt(input.readLine());
System.out.print("c = ");
c = Integer.parseInt(input.readLine());
}
public double proses() {
y = 2 * Math.cos(0.5) * (a + b) + Math.sin(c);
System.out.print("hasil y =");
System.out.println(y);
return y;
}
public static void main(String[] args) throws IOException {
persamaan1 p = new persamaan1();
p.input_data();
p.proses();
}
}
2. Persamaan2 Class persamaan1
public class persamaan2 { int a;
int a; int b;
int b; int c;
int c; double x;
double x;
Input_data()
private void input_data() throws IOException { Proses()
DataInputStream input = new DataInputStream(System.in);
System.out.print("a = ");
a = Integer.parseInt(input.readLine());
System.out.print("b = "); Pt
b = Integer.parseInt(input.readLine());
System.out.print("c = ");
c = Integer.parseInt(input.readLine());
}
public double proses() {
x = (Math.sin(a) + Math.sqrt(Math.pow(b, 2))) / (2 * c);
System.out.print("hasil x =");
System.out.println(x);
return x;
}
public static void main(String[] args) throws IOException {
persamaan2 pt = new persamaan2();
pt.input_data();
pt.proses();
}
}
3. Persamaan3
public class persamaan3 { Class persamaan1
int a; int a;
int b; int b;
int c; int c;
double p; double p;
private void input_data() throws IOException { Input_data()
DataInputStream input = new DataInputStream(System.in); Proses()
System.out.print("a = ");
a = Integer.parseInt(input.readLine());
System.out.print("b = ");
b = Integer.parseInt(input.readLine()); Pth
System.out.print("c = ");
c = Integer.parseInt(input.readLine());
}
public double proses() {
p = 1 + (a/2) + (Math.pow(b,2)/2) + (Math.pow(c,3)/2);
System.out.print("hasil p =");
System.out.println(p);
return p;
}
public static void main(String[] args) throws IOException {
persamaan3 pth = new persamaan3();
pth.input_data();
pth.proses();
}
}
Class loopfor
int a = 2;
4. Looping for int b = 10;
int c = 5;
public class loopfor {
int a = 2;
Proses()
int b = 10;
int c = 5;
public void proses() throws IOException {
System.out.println("No\t a\t b\t c\t persamaan1\t persamaan2");
a
for (int i = 1; i <= 10; i++) {
double y = 2 * Math.cos(0.5) * (a + b) + Math.sin(c);
double x = (Math.sin(a) + Math.sqrt(Math.pow(b, 2))) / (2 * c);
System.out.printf("%-2d\t %-2d\t %-2d\t %-2d\t %-12.2f\t %-12.2f\n", i, a, b, c, y, x);
a += 2;//buat menambah 2 setiap variabel a
b -= 1;//buat mengurangi 1 setiap variabel b
c += 1;//buat menambah 1 setiap variabel c
public static void main(String[] args) throws IOException {
loopfor a = new loopfor();
a.proses();
}
}
Class loopwhile
int a = 2;
int b = 10;
int c = 5;
5. Loop while
public class loopwhile {
Proses()
int a = 2;
int b = 10;
int c = 5;
public void proses() throws IOException { ab
System.out.println("No\t a\t b\t c\t persamaan1\t persamaan2");
int i = 1; // Inisialisasi variabel loop
while (i <= 10) { // Kondisi loop
double y = 2 * Math.cos(0.5) * (a + b) + Math.sin(c);
double x = (Math.sin(a) + Math.sqrt(Math.pow(b, 2))) / (2 * c);
System.out.printf("%-2d\t %-2d\t %-2d\t %-2d\t %-12.2f\t %-12.2f\n", i, a, b, c, y, x);
a += 2; // buat menambah 2 setiap variabel a
b -= 1; // buat mengurangi 1 setiap variabel b
c += 1; // buat menambah 1 setiap variabel c
i++; // Increment variabel loop
}
}
public static void main(String[] args) throws IOException {
loopfor ab = new loopfor();
ab.proses();
}
}
Class loopdowhile
int a = 2;
int b = 10;
int c = 5;
6. Loop do while
Proses()
public class loopdowhile {
int a = 2;
int b = 10;
int c = 5;
abc
public void proses() throws IOException {
System.out.println("No\t a\t b\t c\t persamaan1\t persamaan2");
int i = 1; // Inisialisasi variabel loop
do {
double y = 2 * Math.cos(0.5) * (a + b) + Math.sin(c);
double x = (Math.sin(a) + Math.sqrt(Math.pow(b, 2))) / (2 * c);
System.out.printf("%-2d\t %-2d\t %-2d\t %-2d\t %-12.2f\t %-12.2f\n", i, a, b, c, y, x);
a += 2; // buat menambah 2 setiap variabel a
b -= 1; // buat mengurangi 1 setiap variabel b
c += 1; // buat menambah 1 setiap variabel c
i++; // Increment variabel loop
} while (i <= 10); // Kondisi loop
}
public static void main(String[] args) throws IOException {
loopfor abc = new loopfor();
abc.proses();
}
}
7. Soal 3 data inap
Class datainap
public class datainap { int idtamu;
int idtamu; String kodekamar;
String tglcheckin;
String kodekamar;
int lamainap;
String tglcheckin; int tarifkamar;
int lamainap; int Ttarif;
int tarifkamar; double diskon;
int Ttarif; double Tbayar;
double diskon;
double Tbayar; Input_data()
Prosestarif()
public void input_data() throws IOException {
DataInputStream input = new DataInputStream(System.in);
System.out.print("Input ID Tamu: ");
idtamu = Integer.parseInt(input.readLine()); booking
System.out.print("Input kode kamar: ");
kodekamar = input.readLine();
System.out.print("Input tgl check in: ");
tglcheckin = input.readLine();
System.out.print("Input lama inap: ");
lamainap = Integer.parseInt(input.readLine());
}
public double prosestarif() throws IOException {
switch (kodekamar) {
case "1":
tarifkamar = 300000;
break;
case "2":
tarifkamar = 400000;
break;
case "3":
tarifkamar = 500000;
break;
default:
System.out.println("Kode kamar tidak valid");
return 0;
}
// hitung total tarif
Ttarif = tarifkamar * lamainap;
// hitung diskon
if (lamainap >= 5) {
diskon = 0.05 * Ttarif;
} else {
diskon = 0;
}
// hitung total bayar
Tbayar = Ttarif - diskon;
System.out.print("Tarif Kamar: ");
System.out.println(tarifkamar);
System.out.print("Total Tarif: ");
System.out.println(Ttarif);
System.out.print("Diskon: ");
System.out.println(diskon);
System.out.print("Total Bayar: ");
System.out.println(Tbayar);
return Tbayar;
}
public static void main(String[] args) throws IOException {
datainap booking = new datainap();
booking.input_data();
booking.prosestarif();
}
}