0
I am trying to build a loan calculater program which is in Java Course.. can anyone help me with this? Program is in deacription
Q..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. MY CODE: 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 remainingAmount = amount; for(int i = 0; i < 6; i++){ int payment = (int)(Math.round(remainingAmount * 0.1)); remainingAmount = remainingAmount - payment; } System.out.println(remainingAmount); } }
4 Respostas
0
Thanks for answering but the answer is different...by my solution it is getting the 3 cases right out of 5.
Here is an explanation
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
Month 4:
Payment: 10% of 14580 = 1458
Remaining amount: 13122
Month 5:
Payment: 10% of 13122 = 1313
Remaining amount: 11809
Month 6:
Payment: 10% of 11809 = 1181
Remaining amount: 10628
0
Here's what i have so far, I can only get 3 out of 5 cases to pass and i cant see the result of the two failing cases...
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double amount = scanner.nextDouble();
double total=0;
double sub;
for(int i =0; i < 6; i++){
sub = amount * .10;
total = (amount - sub);
amount = total;
}
int value = (int)total;
System.out.println(value);
}
}
0
Thanks for answering.i got also 3/5 answer correct....but all the cases should be satisfied.