Tugas 4 White Box: 1. Flow Diagram
Tugas 4 White Box: 1. Flow Diagram
Tugas 4 White Box: 1. Flow Diagram
White Box
1. Flow Diagram
Keterangan :
1. input username & password
2. cek if(username = "user")
3. cek if(password = "user")
4. set cek_exit = true
5. set cek_exit = false
6. while(!cek_exit)
7. set pilih -> case pilih = 1(motor)
8. set motor -> case motor = 1(vario)
9. case pilih = 2(mobil)
10. case motor = 2(supra)
11. set data motor vario -> print data motor vario
12. case motor = 3(exit)
13. set mobil -> case mobil = 1(avanza)
14. set data motor supra -> print data motor supra
15. set data mobil avanza -> print data mobil avanza
16 case mobil = 2(calya)
17. set cek_exit = true
18. set data mobil calya -> print data mobil calya
19. break
20. end
2. CC
V(G) = E - N + 2
= 29 - 20 +2
= 11
V(G) = P+1
= 10 +1
= 11
Region = 11
Berdasarkan 3 perhitungan diatas maka diketahui bahwa Cyclomatic Complexity nya
adalah 11.
3. Independent Path
a) 1-2-4-6-20
b) 1-2-3-4-6-20
c) 1-2-3-5-6-7-9-12-17-19-6-20
d) 1-2-3-5-6-7-9-12-19-6-7-9-12-17-6-20
e) 1-2-3-5-6-7-9-13-16-19-6-7-9-12-17-6-20
f) 1-2-3-5-6-7-9-13-16-18-19-6-7-9-12-17-6-20
g) 1-2-3-5-6-7-9-13-15-19-6-7-9-12-17-6-20
h) 1-2-3-5-6-7-8-10-19-6-7-9-12-17-6-20
i) 1-2-3-5-6-7-8-10-14-19-6-7-9-12-17-6-20
j) 1-2-3-5-6-7-8-11-19-6-7-9-12-17-6-20
4. Test Case
a. input username = aaa
b. input password = aaaa
5. Source Code
a. Kelas main
package oop2;
import java.io.ObjectInputStream.GetField;
import java.util.Scanner;
String username,password;
System.out.print("masukkan username :");
username = input.next();
System.out.print("masukkan password :");
password = input.next();
boolean cek_exit;
if (username.equals("user")&&password.equals("user")) {
cek_exit = false;
} else {
cek_exit = true;
System.out.println("login gagal");
}
int pilih;
while (!cek_exit) {
System.out.println("------Pilih Jenis Kendaraan-----");
System.out.println("1. Motor");
System.out.println("2. Mobil");
System.out.println("3. Exit");
System.out.print("Masukan pilihan anda : ");
pilih = input.nextInt();
switch (pilih) {
case 1:
int motor;
System.out.println("Pilih Kendaraan Motor");
System.out.println("1. Honda Vario");
System.out.println("2. Honda Supra");
System.out.print("Masukan pilihan anda : ");
motor = input.nextInt();
switch (motor) {
case 1:
kendaraan motor1 = new kendaraan();
motor1.setJenis_kendaraan("Honda Vario");
motor1.setNopol("R 3498 QC");
motor1.setHarga(2000);
System.out.println("Jenis Kendaraan :
"+motor1.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+motor1.getNopol()+"");
System.out.println("Harga :
"+motor1.getHarga()+"");
System.out.println("Jenis Kendaraan :
"+motor2.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+motor2.getNopol()+"");
System.out.println("Harga :
"+motor2.getHarga()+"");
break;
case 2:
kendaraan motor3 = new kendaraan();
motor3.setJenis_kendaraan("Honda Supra");
motor3.setNopol("R 3498 QC");
motor3.setHarga(2000);
System.out.println("Jenis Kendaraan
:"+motor3.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+motor3.getNopol()+"");
System.out.println("Harga :
"+motor3.getHarga()+"");
System.out.println("Jenis Kendaraan :
"+motor4.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+motor4.getNopol()+"");
System.out.println("Harga :
"+motor4.getHarga()+"");
break;
default:
System.out.println("Kendaraan tidak terdaftar");
break;
}
break;
case 2 :
int mobil;
System.out.println("Pilih Kendaraan Motor");
System.out.println("1. Toyota Avanza");
System.out.println("2. Toyota Calya");
System.out.print("Masukan pilihan anda : ");
mobil = input.nextInt();
switch (mobil) {
case 1:
kendaraan mobil1 = new kendaraan();
mobil1.setJenis_kendaraan("Toyota Avanza");
mobil1.setNopol("B 7869 BH");
mobil1.setHarga(10000);
System.out.println("Kendaraan :
"+mobil1.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+mobil1.getNopol()+"");
System.out.println("Harga :
"+mobil1.getHarga()+"");
System.out.println("Kendaraan :
"+mobil2.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+mobil2.getNopol()+"");
System.out.println("Harga :
"+mobil2.getHarga()+"");
break;
case 2:
kendaraan mobil3 = new kendaraan();
mobil3.setJenis_kendaraan("Toyota Calya");
mobil3.setNopol("K 3457 BB");
mobil3.setHarga(20000);
System.out.println("Kendaraan :
"+mobil3.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+mobil3.getNopol()+"");
System.out.println("Harga :
"+mobil3.getHarga()+"");
System.out.println("Kendaraan :
"+mobil4.getJenis_kendaraan()+"");
System.out.println("No Pol :
"+mobil4.getNopol()+"");
System.out.println("Harga :
"+mobil4.getHarga()+"");
break;
default:
System.out.println("Kendaraan tidak terdaftar");
break;
}
break;
case 3 :
cek_exit = true;
break;
default:
System.out.println("Inputan yang dimasukan salah");
break;
}
}
}
b. Kelas Kendaraan
package oop2;