Java methods | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Java methods

Someone pls help, i dont know what is wrong with my program. https://code.sololearn.com/cykmt5czfxWN/?ref=app

16th Jan 2022, 3:52 PM
Bobby Dike
Bobby Dike - avatar
11 Answers
+ 3
I 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)
16th Jan 2022, 4:10 PM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 3
APURVA KAUSHAL Please create a new question for your problem. Thanks!
18th Jan 2022, 4:32 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
nevermind, i figured it out. thanks for all your help
16th Jan 2022, 5:20 PM
Bobby Dike
Bobby Dike - avatar
+ 1
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
16th Jan 2022, 4:14 PM
Nick
+ 1
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; }
16th Jan 2022, 4:25 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Bobby Dike And here is an example where Scanner keyboard is a static variable: https://code.sololearn.com/c27OzbgJtzeD/?ref=app
16th Jan 2022, 4:28 PM
Denise Roßberg
Denise Roßberg - avatar
0
can you please re write my code, i dont know how to do these
16th Jan 2022, 4:23 PM
Bobby Dike
Bobby Dike - avatar
0
Denise Roßberg Mikolaj Agnes Ahlberg Bahha🐧 the second method in my program does not work as its supposed to.
16th Jan 2022, 4:54 PM
Bobby Dike
Bobby Dike - avatar
0
Bobby Dike Can you give an input/output example and describe how it should work?
16th Jan 2022, 5:06 PM
Denise Roßberg
Denise Roßberg - avatar
0
could you stick around? I might need extra help in a few.
16th Jan 2022, 5:21 PM
Bobby Dike
Bobby Dike - avatar
0
I cant solve time converter how to solve it ?
18th Jan 2022, 1:45 PM
APURVA KAUSHAL