Question: Control flow testing Activity Question 1: Consider the code shown below : package activity9; import java.util.Scanner; public class Activity9 { public static void main(String[] args)

Control flow testing Activity

Question 1: Consider the code shown below :

package activity9;

import java.util.Scanner;

public class Activity9 {

public static void main(String[] args) {

// TODO code application logic hereScanner input = new Scanner(System.in);

int choice = 0;

double celsius, fahrenheit, inches, centimeters;

char doAgain = 'y';

while (doAgain == 'y' || doAgain == 'Y')

{

System.out.print(" Main Menu 1. Celsius to Fahrenheit 2. Inches to Centimeters "

+ "Please select either 1 or 2 Then press enter to continue");

choice = input.nextInt();

if (choice == 1)

{

System.out.println("This program will convert a celsius value into a fahrenheit one. ");

System.out.println("Please enter the tempature for conversion: ");

celsius = input.nextInt();

fahrenheit = 1.8 * celsius + 32.0;

System.out.println(celsius + " degree(s) in celcius" + " is " + fahrenheit +

" in fahrenheit. ");

System.out.println("Do you want to continue? : " +

"enter a \'y \' for another round " +

" enter a\'n\' to end the program ");

doAgain = input.next().charAt(0);

}

else if (choice == 2)

{

System.out.println("This program will convert inches to centimeters. ");

System.out.println("Please enter the length for conversion: ");

inches = input.nextInt();

centimeters = 2.54 * inches;

System.out.println(inches + " inches is " + centimeters + " centimeters. ");

System.out.println("Do you want to continue? : " +

"enter a \'y \' for another round " +

" enter a\'n\' to end the program ");

doAgain = input.next().charAt(0);

}

else

{

System.out.println("That is not a valid option. Please restart and try again");

}

}

}

}

1Draw control flow graph (CFG) for the above code

2Compute the McCabe cyclomatic complexity number

3List the logical paths

4Give an example of the initial values of variables ( doAgain and choice ) to execute each path.

5List the paths that are required to cover all the statements.

6List the paths that are required to cover all the branches.

7List the paths that are required to cover all the paths

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!