Question
1. Draw the control flow graph and design test cases to perform basic path testin 2. Implement Junit code to run test cases for each
1. Draw the control flow graph and design test cases to perform basic path testin
2. Implement Junit code to run test cases for each path
3. design test cases for D-U path testing for variables occupancyRate and totalOccupied.
4. Identify bugs in the program using test cases b and c above and fix them
// Hotel Suites occupancy
// This program calculates the occupancy rate for a hotel's suites.
// These are located on floors 10-16. There is no 13th floor.
import java.util.Scanner;
import java.text.*;
public class hotelOccupancy
{
public void calcRate()
{
final int
SUITES_PER_FLOOR = 20, // Number of suites per floor
MIN_FLOOR = 10, // Lowest floor of suite units
MAX_FLOOR = 16, // Highest floor of suite units
TOTAL_SUITES = (MAX_FLOOR - MIN_FLOOR) * SUITES_PER_FLOOR;
Scanner scan = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat();
int occupied, // Number of occupied suites on the floor
totalOccupied = 0; // Total number of occupied suites
double occupancyRate; // % of the suites that are occupied
// Get and validate occupancy information for each floor
System.out.println("Enter the number of occupied suites on each of the following floors. ");
for (int floor = MIN_FLOOR; floor <= MAX_FLOOR; floor++)
{
if (floor == 13)
continue; // Skip thirteenth floor
System.out.println(" Floor " + floor+ ": ");
occupied=scan.nextInt();
while (occupied < 0 && occupied > SUITES_PER_FLOOR)
{
System.out.println(" The number of occupied suites must be between 0 and " + SUITES_PER_FLOOR );
System.out.println(" Re-enter the number of occupied suites on floor " + floor + ": ");
occupied = scan.nextInt();
}
// Add occupied suites on this floor to the total
totalOccupied += occupied;
}
// Compute occupancy rate in % form
occupancyRate = 100* totalOccupied / TOTAL_SUITES;
// Display results
System.out.println(" The hotel has a total of " + TOTAL_SUITES + " suites. ");
System.out.println(totalOccupied+ " are currently occupied. ");
System.out.println("This is an occupancy rate of " + fmt.format(occupancyRate)+ "% ");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started