Question: PARTICIPATION ACTIVITY 4 . 1 . 5 : Handling input exceptions: restaurant max occupancy tracker. Full screen Arrange the following lines to make a program

PARTICIPATION
ACTIVITY
4.1.5: Handling input exceptions: restaurant max occupancy tracker.
Full screen
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 InputMismatchException 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.
How to use this tool v
Unused
while (totalNumPeople maxNumPeople){
System.out.println("Occupancy: "+ totalNumPeople);
try {
totalNumPeople += scnr. nextInt();
}
catch (InputMismatchException e){
scnr.nextLine();
}
catch {
scnr.next ();
}
System.out.println("Error");
MaxOccupancyTracker.java
Load default template...
import java.util.Scanner;
import java.util. InputMismatchException;
public class Max0ccupancyTracker { public static void main(String [] args){
Scanner scnr = new Scanner(System. in);
int maxNumPeople =10;
int totalNumPeople =0;
System. out.println("We're full!"); }}}
 PARTICIPATION ACTIVITY 4.1.5: Handling input exceptions: restaurant max occupancy tracker. Full

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!