Does anyone know how to solve the problem: Checking or Saving from the Java course? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Does anyone know how to solve the problem: Checking or Saving from the Java course?

I should override the method for saving and checking account. The output is always 0.00. I don't know what I'm doing wrong. Link to the problem: https://www.sololearn.com/coach/807?ref=app

22nd Apr 2021, 12:23 PM
Denisa Zaharia
Denisa Zaharia - avatar
9 Answers
+ 3
amount has private access. You need to use getAmount(). Btw: you don't need an extra variable to return the value: return getAmount() + getAmount() * 0.2; return getAmount() + getAmount() * 0.05;
22nd Apr 2021, 2:33 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Hello Denisa Zaharia Can you please share your overridden methods? In the task you can not see the codes from other users.
22nd Apr 2021, 2:04 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you so much!
22nd Apr 2021, 6:30 PM
Denisa Zaharia
Denisa Zaharia - avatar
0
Please post your attempt so that we can look into it
22nd Apr 2021, 12:29 PM
Aditya
Aditya - avatar
22nd Apr 2021, 12:30 PM
Denisa Zaharia
Denisa Zaharia - avatar
0
I can't view the problem.. since I'm not a pro user. Can you please paste the problem along with your code?
22nd Apr 2021, 1:12 PM
Aditya
Aditya - avatar
0
class SavingAcc extends Account { public SavingAcc(double amount) { super(amount); } /*Override the method for saving account public double getIncome(double amount) { double saving; saving = amount + amount*0.2; return saving; } */ } class CheckingAcc extends Account { public CheckingAcc(double amount) { super(amount); } /*Override the method for checking account public double getIncome(double amount) { double checking; checking = amount + amount*0.05; return checking; } */ }
22nd Apr 2021, 2:18 PM
Denisa Zaharia
Denisa Zaharia - avatar
0
Denisa Zaharia Your welcome!
22nd Apr 2021, 6:44 PM
Denise Roßberg
Denise Roßberg - avatar
0
I first ran this by making the super class amount to public, but I know I am not supposed to change that to public. So I checked here and saw the getAmount method and that made more sense. The only thing is, is that I had to run the same code multiple time before it ran all correctly because I would get execution timed out as an output for some.
18th May 2021, 11:47 AM
Vixey
Vixey - avatar