Question: Arrange the following lines to make a program that determines when the number of people in a restaurant equals or exceeds 10 occupants. The

Arrange the following lines to make a program that determines when the number of people in a restaurant equals or exceeds 10 occupants. The program continually gets the number of people entering or leaving the restaurant. Ex: 2 means two people entered, and -3 means three people left. After each input, the program outputs the number of people in the restaurant. Once the number of people in the restaurant equals or exceeds 10, the program exits. If an InputMismatch Exception exception occurs, the program should get and discard a single string from input. Ex: The input "2 abc 8 should result in 10 occupants. Not all lines are used in the solution. Mouse: Drag/drop Keyboard: Grab/release Spacebar (or Enter). Move D000. Cancel (Esc Unused catch { scnr.nextLine(); Check You've added 11 blocks, but 10 were expected. Not all tests passed. MaxOccupancy Tracker.java while (totalNumPeople < maxNumPeople) { try { totalNumPeople += scnr.nextInt (); if (totalNumPeople < 0) { totalNumPeople = 0; } System.out.println("Occupancy: " + totalNumPeople); } catch (InputMismatch Exception e) { scnr.next(); System.out.println("Error"); } Load default template... } Arrange the following lines to make a program that determines when the number of people in a restaurant equals or exceeds 10 occupants. The program continually gets the number of people entering or leaving the restaurant. Ex: 2 means two people entered, and -3 means three people left. After each input, the program outputs the number of people in the restaurant. Once the number of people in the restaurant equals or exceeds 10, the program exits. If an InputMismatch Exception exception occurs, the program should get and discard a single string from input. Ex: The input "2 abc 8 should result in 10 occupants. Not all lines are used in the solution. Mouse: Drag/drop Keyboard: Grab/release Spacebar (or Enter). Move 0000. Cancel (Esc Unused System.out.println("Occupancy: " + totalNumPeople); } } catch (InputMismatchException e) { try { catch { while (totalNumPeople < maxNumPeople) { if (totalNumPeople < 0) { totalNumPeople = 0; } } System.out.println("Error"); scnr.next(); MaxOccupancy Tracker.java Load default template.... import java.util.Scanner; import java.util. InputMismatchException; public class MaxOccupancy Tracker { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int maxNumPeople = 10; int totalNumPeople = 0; System.out.println("We're full!");
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
