0

Urgent!!) I have a question Guys!

** Could you guys write with Java please? Thanks :) I'd like to solve about Java Module 2 test in this Site. The Problem is... Loan Calculator You take a loan from a friend and need to calculate how much you will owe him after 3 months. You are going to pay him back 10% of the remaining loan amount each month. Create a program that takes the loan amount as input, calculates and outputs the remaining amount after 3 months. Sample Input: 20000 Sample Output: 10628 Here is the monthly payment schedule: Month 1 Payment: 10% of 20000 = 2000 Remaining amount: 18000 Month 2 Payment: 10% of 18000 = 1800 Remaining amount: 16200 Month 3: Payment: 10% of 16200 = 1620 Remaining amount: 14580 Thus, I make a code which can solve this problem. like this, import java.util.Scanner; public class LoanProject { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("input money : "); int amount = sc.nextInt(); for (int j = 0; j <=2; j++) { int pay = (int)(amount * 0.1); int total = (amount - pay); System.out.println("Payment: 10% of "+ amount+" = "+ pay); System.out.println("Remaining amount : " + total); amount = total; System.out.println(); } } } How can i solve this problem? And which area i did wrong? If you guys find the answer and solution, please let me know. Thanks for your help :)

23rd Aug 2021, 8:16 AM
Invisible Sight
Invisible Sight - avatar
7 odpowiedzi
+ 2
It's not necessary to add extra informations in your solution. import java.util.Scanner; public class LoanProject { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //System.out.print("input money : "); int amount = sc.nextInt(); int total = amount; for (int j = 0; j <=2; j++) { int pay = (int)(amount * 0.1); total = (amount - pay); amount = total; //System.out.println("Payment: 10% of "+ amount+" = "+ pay); } System.out.println(total); //amount = total; //System.out.println(); } }
23rd Aug 2021, 9:17 AM
Simba
Simba - avatar
+ 3
But, Sololearn doesn't need them since it's a bot. I mean your output should be matched with expected output. Hope you know Java is a case sensitive language
23rd Aug 2021, 5:07 PM
Simba
Simba - avatar
+ 1
//dnt use all that outputs For(int i = 0 ; i <=3; i++){ Int res = (amount*10)/100; amount = amount - res ; } S.o.p(amount);
24th Aug 2021, 6:02 PM
Nipun
Nipun - avatar
0
Use double type , int will convert something like 234.5 to 234
23rd Aug 2021, 8:20 AM
Abhay
Abhay - avatar
0
Please don't use tags that have nothing to do with your question. You tagged six languages that have nothing to do with your question.
23rd Aug 2021, 8:27 AM
Simon Sauter
Simon Sauter - avatar
0
I knew that, but it's really urgent thing i felt So sorry :( PS: Edited!
23rd Aug 2021, 8:28 AM
Invisible Sight
Invisible Sight - avatar
0
Simba, Thanks for your help. However, I need extra information and tips why do not necessary to add extra information? I guess that I should write print about print line like //System.out.print("input money : "; Could you explain why do not need these lines?
23rd Aug 2021, 3:23 PM
Invisible Sight
Invisible Sight - avatar