Professional Documents
Culture Documents
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.*;
}//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());
}
//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