Home /
Expert Answers /
Computer Science /
need-help-to-solve-this-thank-you-begin-tabular-l-l-participation-13-1-5-handling-input-exc-pa339
(Solved):
Need help to solve this!
Thank you
\begin{tabular}{l|l} PARTICIPATION & 13.1.5: Handling input exc ...
Need help to solve this!
Thank you
\begin{tabular}{l|l} PARTICIPATION & 13.1.5: Handling input exceptions: restaurant max occupancy tracker. \\ ICTIVITY & \end{tabular} 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. Mouse: Drag/drop Keyboard: Grab/release (or Move Cancel \( \mathbf{E s c} \) MaxOccupancyTracker.java Load default template... import java.util.Scanner; import java.util.InputMismatchexception; public class MaxoccupancyTracker \{ public static void main(String [] args) \{ int maxNumPeople \( =10 \); int totalnumpeople \( =0 \); while (totalNumPeople \( < \) maxNumPeople) \{ totalNumPeople \( +=\operatorname{scn} r \). nextInt(); System.out.println( "Occupancy: " + totalnumPeople); System.out.println("We're full!"); You've added 5 blocks, but 9 were expected. Not all tests passed.
1: Compare output \( \boldsymbol{\wedge} \) 2: Compare output \( \boldsymbol{\wedge} \) \begin{tabular}{l|ll} & Input & \( 8-35 \) \\ output & Occupancy: 8 Occupancy: 5 Occupancy: 10 We're full! \end{tabular} \( \times \) 3: Compare output \( \boldsymbol{\wedge} \) Exception in thread "main" java.util. InputMismatchException at java.base/java.util.Scanner.throwFor (Scanner.java:939) at java.base/java. util.Scanner.next (Scanner.java:1594) at java.base/java. util. Scanner. nextInt (Scanner.java:2258) at java.base/java.util.Scanner.nextint (Scanner.java:2212) at MaxOccupancyTracker.main (MaxOccupancyTracker.java:11) \begin{tabular}{l|ll|} \hline Input & 5 & \( -2 \) one \\ 7 & \end{tabular} \begin{tabular}{l|l} Your output Occupancy: 5 \\ Occupancy: 3 \end{tabular}
\( \times \) 4: Compare output \( \boldsymbol{\Lambda} \) Exception in thread "main" java.util. InputMismatchException at java.base/java. util.Scanner.throwFor (Scanner.java:939) at java.base/java.util.Scanner.next (Scanner.java:1594) at java.base/java. util.Scanner.nextInt (Scanner.java:2258) at java.base/java. util.Scanner.nextint (Scanner.java:2212) at MaxOccupancyTracker.main (MaxOccupancyTracker.java:11) Input Your output Your program produced no output Expected output 5: Compare output \( \boldsymbol{\wedge} \) Input Occupancy: 7 Occupancy: 4