HI! CAN ANYONE HELP ME IN A CODE COACH PROBLEM IN JAVA? THE LOAN CALCULATOR | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

HI! CAN ANYONE HELP ME IN A CODE COACH PROBLEM IN JAVA? THE LOAN CALCULATOR

You take a loan from a friend and need to calculate how much you will owe him after 6 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 6 months. Sample Input: 20000 Sample Output: 10628 Here is the monthly payment schedule: Month 1 Payment: 10% of 20000 = 2000 Remaining amount: 18000 Month 6: Payment: 10% of 11809 = 1181 Remaining amount: 10628 If you input 100000 just like the input in the problem, My answer is 53144.1 and then java rounds it up then it makes my answer 53145, the output is 53144. The one who created that problem must have made a mistake. I deserve XP if this is proven, I've spent 4 days solving this. My guess is the creator used a calculator to calculate the output. https://code.sololearn.com/ckbyObI2Ilz3/?ref=app

9th Dec 2020, 4:05 PM
Danziel Cempron
11 Answers
+ 2
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here int i; for(i=0; i<6; i++) amount*=0.9; System.out.println(amount); } }
8th Jan 2021, 3:30 PM
Anuj Singh
Anuj Singh - avatar
9th Dec 2020, 4:41 PM
Brian
Brian - avatar
+ 1
Yes. They should've indicated that you will use Math class and typecasting which is so many lessons away from the problem. I've spent 4 days solving this and now I'm happy with my answer hahahs. https://code.sololearn.com/ckbyObI2Ilz3/?ref=app
10th Dec 2020, 2:15 AM
Danziel Cempron
+ 1
import java.util.Scanner; import java.lang.*; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(int i=0;i<6;i++){ int payment =(int)(10*amount )/100; if((amount%10)!=0){ amount =amount-1; } amount = amount- payment ; } System .out .print(amount); } }
24th Jan 2021, 9:48 AM
Mutlu Eren
Mutlu Eren - avatar
0
Is my answer wrong?
9th Dec 2020, 4:47 PM
Danziel Cempron
0
Danziel Cempron IMHO your answer is not wrong. However, to satisfy Code Coach use the ceiling value of amount/10. EDIT: Tip: That also entails changing the calculation from integer to floating point.
9th Dec 2020, 4:52 PM
Brian
Brian - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); for(int month=1; month<4; month++){ amount-=(amount*10)/100; } System.out.println(amount); } }
5th Apr 2021, 1:58 PM
Avani N
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here float payment = 0; int i = 0; while(i<3){ payment = (float)(amount * 0.1); amount = (int)(amount - payment); i++; } System.out.print(amount); } }
18th Apr 2021, 8:39 AM
Rakesh Gombi
Rakesh Gombi - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println(" Enter loan amount :"); float loanamount = scanner.nextInt(); for(int month=1;month<3;month++) { float Payment=0.1*loanamount; float remainingamount=loanamount-Payment: System.out.println(" Payment : 10% of " + loanamount + "=" + Payment); System.out.println(" Remaining amount :" + " "+ remainingamount); if(month == 3) { break; } } System.out.println(" Remaining amount :" + " "+ remainingamount); //your code goes here } }
22nd Apr 2021, 5:28 AM
dudly tabahi.
dudly tabahi. - avatar
0
Print only what is necessary....remove unwanted output statements and line
22nd Apr 2021, 1:31 PM
Rakesh Gombi
Rakesh Gombi - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for (int i = 1; i < 4; i++) { amount *= .9; if (i == 3) { System.out.println(amount); } } } }
5th Sep 2021, 3:43 AM
Fabrice Innocent