The Jetbrains Academy Java “Project: Cinema Room Manager” at stage 4/5 throws an unclear error Program ran out of input. You tried to read more, than expected....
. The Java stack trace is:
at org.hyperskill.hstest.stage.StageTest.start(StageTest.java:131) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38) at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164) at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) at java.base/java.lang.Thread.run(Thread.java:834)
Source code
SeatPlanning.java
package cinema; import java.util.Scanner; public class SeatPlanning { private int rows; private int seatsPerRow; private String[][] seats; private final Scanner s; public SeatPlanning() { s = new Scanner(System.in); } public int getTicketPrice(int row) { int totalSeats = rows * seatsPerRow; if (totalSeats <= 60) { return 10; } else { int frontRows = (int) Math.floor((double) rows / 2); return (row <= frontRows) ? 10 : 8; } } public void printTicketPrice(int row) { System.out.printf("Ticket price: $%dn", getTicketPrice(row)); } private void printInputRequest(String str) { System.out.printf("%sn", str); System.out.print("> "); } public void launch() { printInputRequest("Enter the number of rows:"); rows = s.nextInt(); printInputRequest("Enter the number of seats in each row:"); seatsPerRow = s.nextInt(); initSeats(); printMenu(); } private void initSeats() { this.seats = new String[rows][seatsPerRow]; for (int row = 0; row < rows; row++) { for (int column = 0; column < seatsPerRow; column++) { this.seats[row][column] = " S"; } } } public void printSeats() { System.out.print("nCinema:n "); for (int column = 0; column < seatsPerRow; column++) { System.out.printf(" %d", column + 1); } System.out.print("n"); for (int row = 0; row < rows; row++) { System.out.printf("%d", row + 1); for (int column = 0; column < seatsPerRow; column++) { System.out.print(seats[row][column]); } System.out.print("n"); } } private void buySeat(int row, int column) { this.seats[row - 1][column - 1] = " B"; printTicketPrice(row); } public void startBuySeatDialog() { printInputRequest("Enter a row number:"); int row = s.nextInt(); printInputRequest("Enter a seat number in that row:"); int column = s.nextInt(); buySeat(row, column); } public void printMenu() { printInputRequest("n1. Show the seatsn" + "2. Buy a ticketn" + "0. Exit"); evaluateMenuOption(s.nextInt()); } private void evaluateMenuOption(int option) { switch (option) { case 0: System.exit(0); case 1: this.printSeats(); this.printMenu(); break; case 2: this.startBuySeatDialog(); this.printMenu(); } } }
Cinema.java
package cinema; public class Cinema { public static void main(String[] args) { SeatPlanning seatPlanning = new SeatPlanning(); seatPlanning.launch(); } }
Advertisement
Answer
You might have used System.exit(0)
to quit the application which is the culprit of the problem.
Instead, use return
to quit the application.