TUGAS INDIVIDU
“ SOFTWARE ENGINEERING ” ” DOSEN : Dr. Ir. Gunadi Nurcahyo, M.Sc
D i s u s u n Oleh : NAMA AMA
: RIVA IVALRI LRI RIS! RIS!IA IAN! N!O O "ONDR ONDRO O
NO. #$
: %&&'&%())
ELAS
: ** + #
MAGIS!ER ILM OM$!ER NIVERSI!AS $!RA INDONESIA “-$!” $ADANG &(%'
Da/ar Isi
White Box Testing Flowgraph Independent Path
0hi/e #o1 !es/in2.
Here is some a!a "ode that reads in dail# data $or rain$all% a!erage windspeed and ho&rs o$ s&n $or a n&m'er o$ da#s and prints o&t s&mmar# statisti"s( Use a program $low graph to show the paths thro&gh the program and to "al"&late the "#"lomati" "omplexit#( This sho&ld determine the n&m'er o$ independent paths( Now ma)e &p some data to test ea"h path( import java.io.*; import java.text.*; public class Weather{
private static BuferedReader keyb = ne BuferedReader! ne "nput#treamReader!#ystem.in$$; public static void %etWeather#tats!int &umber'()ays$ {
int ij; int )ata+,+, = ne int+&umber'()ays,+-,; /0) array (or the eather
data #trin% 1ype+, = {2Rain(all2 2Wind#peed2 23ours o( #un24; 50) array (or type o( data read in the data (or!i=6; i7&umber'()ays; i88$ { (or!j=6; j7-; j88$ { #ystem.out.print!29nter 2 8 1ype+j, 8 2 (or day 2 8 i 8 2: 2$; try{ )ata+i,+j, = "nte%er.parse"nt!keyb.readine!$$; 4
catch !"'9xception e${ #ystem.out.println!2<< 9rror tryin% to read an int 0 ero returned <<2$; )ata+i,+j, = 6; 4
4(or j #ystem.out.println!$; 4(or i
menu int choice=6;
hile !choice == 6$ { #ystem.out.println!2#tats (or2$;
#ystem.out.println!2>t5. Rain2$; #ystem.out.println!2>t/. Wind2$; #ystem.out.println!2>t-. #un>n2$; #ystem.out.println!2>t?hoice: 2$;
try{ choice = "nte%er.parse"nt!keyb.readine!$$; 4
catch !"'9xception e${ #ystem.out.println!2<< ?hoose beteen 5 and - please <<2$; choice = 6; 4
reports int total = 6; sitch !choice$ {
case 5: avera%e rain (or!i=6; i7&umber'()ays; i88$ { total = total 8 )ata+i,+6,; 4(or i #ystem.out.println!2>n@vera%e Rain = 2 8
total&umber'()ays$;
break; case /: avera%e ind (or!i=6; i7&umber'()ays; i88$ { total = total 8 )ata+i,+5,; 4(or i #ystem.out.println!2>n@vera%e Wind#peed = 2 8
total&umber'()ays$;
break; case -:avera%e sun (or!i=6; i7&umber'()ays; i88$ { total = total 8 )ata+i,+/,; 4(or i #ystem.out.println!2>n@vera%e 3ours #un = 2 8
total&umber'()ays$; break; de(ault: choice = 6; 4sitch 4hile #ystem.out.println!$;
4main 4Weather
Flowgraph import a!a(io(*+ import a!a(text(*+ p&'li" "lass Weather, pri!ate stati" B&$$ered-eader )e#' . new B&$$ered-eader/ new Inp&tStream-eader/S#stem(in00+ p&'li" stati" !oid getWeatherStats/int N&m'er1$Da#s0 ,
1
int i%+
int wData2323 . new int2N&m'er1$Da#s3243+ 5567D arra# $or the weather data 2
String wT#pe23 . ,8-ain$all8% 8WindSpeed8% 8Ho&rs o$ S&n89+ 55:7D arra# $or
t#pe o$ data 55read in the data $or/i.;+ i
3
4
, S#stem(o&t(print/8>nter 8 = wT#pe23 = 8 $or da# 8 = i = 8? 80+ tr#, wData2i323 . Integer(parseInt/)e#'(read@ine/00+ 9
6
"at"h /I1>x"eption e0, S#stem(o&t(println/8 >rror tr#ing to read an int 7 ero ret&rned 80+ wData2i323 . ;+ 9 955$or
8
S#stem(o&t(println/0+ 955$or i
9
55men& int "hoi"e.;+
while /"hoi"e .. ;0
10
, S#stem(o&t(println/8Stats $or80+ S#stem(o&t(println/8Ct:( -ain80+ S#stem(o&t(println/8Ct6( Wind80+ S#stem(o&t(println/8Ct4( S&nCn80+ S#stem(o&t(println/8Cthoi"e? 80+
tr#,
12
11
7
5
"hoi"e . Integer(parseInt/)e#'(read@ine/00+ 9
13
"at"h /I1>x"eption e0,
S#stem(o&t(println/8 hoose 'etween : and 4 please 80+ "hoi"e . ;+ 9
14
55reports int total . ;+ 15
swit"h /"hoi"e0 ,
16
"ase :? 55a!erage rain
$or/i.;+ i
17
, total . total = wData2i32;3+ 955$or i 19
18
S#stem(o&t(println/8CnA!erage -ain . 8 =
total5N&m'er1$Da#s0+
'rea)+ 20
"ase 6? 55a!erage wind
$or/i.;+ i
21
, total . total = wData2i32:3+ 955$or i 23
22
S#stem(o&t(println/8CnA!erage WindSpeed . 8 =
total5N&m'er1$Da#s0+
'rea)+ "ase 4?55a!erage s&n
24
$or/i.;+ i
26
, total . total = wData2i3263+ 955$or i
27
S#stem(o&t(println/8CnA!erage Ho&rs S&n . 8 = total5N&m'er1$Da#s0+ 'rea)+ de$a<? "hoi"e . ;+ 955swit"h 955while
28
S#stem(o&t(println/0+ 955main 955Weather
31
30
29
Independent Path
Gambar Independent Part
#lomati" "omplexit# . n&m'er o$ edges E n&m'er o$ nodes = 6
. /;74:0=6 .=6 . ::
A6 -5 /
= Banyak anah = Banyak Bulatan = Cententuan
:(
:%6%4%%%%J%4
6(
:%6%4%%%J%4
4(
:%6%4%%%%J%4%K%6 5 :%6%4%%%J%4%K%6
(
:%6%%:;%::%:6%:4%:%:%:%:J%:
(
:%6%%:;%::%:6%:4%:%:%6;%6:%6;
(
:%6%%:;%::%:6%:4%:%:%6%6%6
J(
:%6%%:;%::%:6%:%:%:%:J%:
K(
:%6%%:;%::%:6%:%:%6;%6:%6;
(
:%6%%:;%::%:6%:%:%6%6%6
:;(
:%6%%:;%::%:6%:4%:%:%:%:K%:%6K%:; 5 :%6%%:;%::%:6%:4%:%:%6;%66%64%6K%:; 5 :%6%%:;%::%:6%:4%:%:%6%6%6J%6K%:; 5 :%6%%:;%::%:6%:%:%:%:K%:%6K%:; 5 :%6%%:;%::%:6%:%:%6;%66%64%6K%:; 5 :%6%%:;%::%:6%:%:%6%6%6J%6K%:;
::(
:%6%%:;%6%4;%4: