Someone pls help, i dont know what is wrong with my program. https://code.sololearn.com/cykmt5czfxWN/?ref=app
1/16/2022 3:52:15 PM
Bobby Dike11 Answers
New AnswerI would say it is the use of multiple Scanner objects. To get rid of them, you have multiple possibilities: 1) use a static field Scanner keyboard in the Painter class. 2) pass the Scanner object to the methods that use them 3) read all input in main and pass the values to the methods (if they need them)
It might be caused by creating two Scanners opening the same System.in stream. Don't instantiate new Scanner in the method when you already opened the stream with other one in the main body
remove the Scanner in roomArea() pass the already created one to the function. //call dim=roomArea(keyboard); //definition public static double roomArea(Scanner keyboard ) { //Scanner keyboard=new Scanner(System.in); double dim; System.out.print("Enter the total area of walls: "); dim=keyboard.nextDouble(); System.out.print("Dimension: "+dim+ "sq ft"); return dim; }
Bobby Dike And here is an example where Scanner keyboard is a static variable: https://code.sololearn.com/c27OzbgJtzeD/?ref=app
Denise Roßberg Mikolaj Agnes Ahlberg Bahha🐧 the second method in my program does not work as its supposed to.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message