Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The program works by randomly generating the winning numbers. This makes testing difficult. One way around this is
to test part of the program separately. We could make a test version of the program which always has the winning
numbers as 1,2,3,4,5,6,7.
Create in a table which lists the test cases, the test data, the expected output and the actual output for the lottery
simulation program.
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