0% found this document useful (0 votes)
103 views3 pages

Gambarkan Flowgraph Utk Flowchart Berikut Ini

1. The program reads in daily weather data (rainfall, windspeed, hours of sun) for a number of days and calculates summary statistics. 2. A flow graph is used to show the program paths and calculate cyclomatic complexity to determine the number of independent paths. 3. Test data should be created to test each path.

Uploaded by

Daniel Theodorus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views3 pages

Gambarkan Flowgraph Utk Flowchart Berikut Ini

1. The program reads in daily weather data (rainfall, windspeed, hours of sun) for a number of days and calculates summary statistics. 2. A flow graph is used to show the program paths and calculate cyclomatic complexity to determine the number of independent paths. 3. Test data should be created to test each path.

Uploaded by

Daniel Theodorus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Gambarkan Flowgraph utk flowchart berikut ini:

2. White Box Testing.

Here is some java code that reads in daily data for rainfall, average windspeed and hours of sun for a number of days
and prints out summary statistics. Use a program flow graph to show the paths through the program and to calculate
the cyclomatic complexity. This should determine the number of independent paths. Now make up some data to test
each path.

import java.io.*;
import java.text.*;

public class Weather{

private static BufferedReader keyb = new BufferedReader(


new InputStreamReader(System.in));

public static void getWeatherStats(int NumberOfDays)


{ int i,j;
int wData[][] = new int[NumberOfDays][3]; //2-D array for the weather data
String wType[] = {"Rainfall", "WindSpeed", "Hours of Sun"}; //1-D array for type of data

//read in the data


for(i=0; i<NumberOfDays; i++)
{ for(j=0; j<3; j++)
{ System.out.print("Enter " + wType[j] + " for day " + i + ": ");
try{
wData[i][j] = Integer.parseInt(keyb.readLine());
}

catch (IOException e){


System.out.println("!! Error trying to read an int - zero returned !!");
wData[i][j] = 0;
}

}//for j
System.out.println();
}//for i

//menu
int choice=0;

while (choice == 0)
{ System.out.println("Stats for");
System.out.println("\t1. Rain");
System.out.println("\t2. Wind");
System.out.println("\t3. Sun\n");
System.out.println("\tChoice: ");

try{
choice = Integer.parseInt(keyb.readLine());
}

catch (IOException e){


System.out.println("!! Choose between 1 and 3 please !!");
choice = 0;
}

//reports
int total = 0;
switch (choice)
{ case 1: //average rain
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][0];
}//for i
System.out.println("\nAverage Rain = " + total/NumberOfDays);
break;
case 2: //average wind
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][1];
}//for i
System.out.println("\nAverage WindSpeed = " + total/NumberOfDays);
break;
case 3://average sun
for(i=0; i<NumberOfDays; i++)
{ total = total + wData[i][2];
}//for i
System.out.println("\nAverage Hours Sun = " + total/NumberOfDays);
break;
default: choice = 0;
}//switch
}//while
System.out.println();
}//main
}//Weather

You might also like