+ 1

Outputting a method, Java

Please I need help, emergency 😳 Please show me how to correct line 43: https://sololearn.com/compiler-playground/cABwV8ZWSRsl/?ref=app

17th May 2025, 6:01 PM
Code Flash
Code Flash - avatar
9 Respuestas
+ 6
I don't think the error is where you think it is... For starters, you have a println with your cal.Xxx() which should call the switch method and that has println statements inside it... are you expecting to println a println? Rethink your code - maybe take out a pen and paper and draw/write what it should do, how should the input be called, passed and handled? Then, I think you'll fix it.
17th May 2025, 6:27 PM
Ausgrindtube
Ausgrindtube - avatar
+ 5
your code is unnecessarily complicated... why does everything have to be separate classes? OOP is best kept simple. Implementing it this way is just extra work with no benefit. And the current trend for more efficient code is to move away from OOP.
18th May 2025, 3:04 AM
Bob_Li
Bob_Li - avatar
+ 3
Code Flash Your GiveAnswer() is a void function(doesn't return anything, simply does tasks and uses println). But you're trying to output its returned value by using println(cal.GiveAnswer()). Since your function already outputs values, you don't need to use println. As Ausgrindtube said, you're trying to println a println. Simply call the function, no need to use println to call it. And I'd suggest you to take the Java course and learn about functions and return values. You should check it before creating codes like this, as you'll be stuck.
18th May 2025, 2:58 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 2
PrintAnswer.java:9: error: <identifier> expected System.out.println(^cal.GiveAnswer()); > so look at fields of that class: class PrintAnswer extends Calculate { Calculate cal = new Calculate(); // first field ok System.out.println(cal.GiveAnswer()); // second, .. wait, that's not a field ! /* println() should be in some method(), else compiler expects field identifier */ }
18th May 2025, 10:57 PM
zemiak
+ 1
Ausgrindtube I couldn't find a replacement for println, please can you tell me the solution 🙏
17th May 2025, 6:36 PM
Code Flash
Code Flash - avatar
+ 1
I appreciate your work, and I would like to request to study the OOPS principle clearly and then do the program. It's not following the principle. Also, you must know the main method. That's where all the program starts.
19th May 2025, 10:17 AM
Anand
Anand - avatar
+ 1
2 errors
19th May 2025, 4:47 PM
Cristiano Ronaldo
Cristiano Ronaldo - avatar
+ 1
I really think this is a Rube Goldberg machine (https://en.wikipedia.org/wiki/Rube_Goldberg_machine), but if you must extend classes, maybe this way: https://sololearn.com/compiler-playground/cd4g5pnJIbXA/?ref=app
20th May 2025, 12:35 AM
Bob_Li
Bob_Li - avatar
0
Hey but I learned methods and I'm currently in java intermediate with my other sololearn account, I just got stock, am I being underestimated because this account is just in level 3?
18th May 2025, 6:39 PM
Code Flash
Code Flash - avatar