+ 1
Report an issue on Loops quiz
Hello I verified my code on eclipse and is resolving the requested on the loops quiz. Can you please review and count it as good. Page does not count it as resolved. import java.util.Scanner; public class Quiz_Loops { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int amount = sc.nextInt(); int i=1; do{ int monthlyPymt = ((amount * 10)/100); int balance = amount - monthlyPymt; amount = balance; System.out.println("Month "+i); System.out.println("Payment 10% of "+amount+" = " +monthlyPymt); System.out.println("Remaining Amount: "+balance); i+=1; //counter incremental } while (i<=3); // ending do while } }
9 odpowiedzi
+ 2
A pgrs
Your problem is the print statement in your while loop.
You need to print only the amount after three month.
input: 20000
output: 10628
Not more. The monthly payment schedule is only for you to understand how to calculate it. It does not mean that you need to print every month.
Means, you need to print monthlyPymt after your do while loop.
+ 1
What is quiz question? Expected output and your output?
What is your actual doubt here.. Clarify it pls....
+ 1
Hi thank you for your quick assistance,
this is the Exercise
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
At the end my code in my question complies showing and printing what is requested however is not being counted as resolved
+ 1
I did that as well
if you see output is wrong ,
why output 10628 is not the same after 3 months for 20000 out put should be 14580 and not 10628 that will be after 6 months,
It is clearly if you run my code you will see what I am talking about,
you can change int i counter as <= 6 and it will give the amount as the output.
there is an error on this exercise.
+ 1
put my code and this is what is shows.
import java.util.Scanner;
public class Quiz_Loops {
public static void main(String[] args) {
System.out.println("Loan Amount: ");
Scanner sc = new Scanner(System.in);
int amount = sc.nextInt();
int i=1;
do{
int monthlyPymt = ((amount * 10)/100);
int balance = amount - monthlyPymt;
amount = balance;
System.out.println("Month "+i);
System.out.println("Payment 10% of "+amount+" = "
+monthlyPymt);
System.out.println("Remaining Amount: "+balance);
i+=1; //counter incremental
}
while (i<=6); // ending do while
}
}
TEST CASE 1
100000
EXPECTED OUTPUT 72900
my code 72900
TEST CASE 2
500000
EXPECTED OUTPUT 364500
my code 364500
+ 1
I resolved it anyways,
Thanks
import java.util.Scanner;
public class Quiz_Loops {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int amount = sc.nextInt();
int i=1;
do{
int monthlyPymt = ((amount * 10)/100);
int balance = amount - monthlyPymt;
amount = balance;
//System.out.println("Month "+i);
//System.out.println("Payment 10% of "+amount+" = "
//+monthlyPymt);
//System.out.println("Remaining Amount: "+balance);
if (i==3){
System.out.println(balance);
break;
}
else {
i+=1; //counter incremental
}
}
while (i<=3); // ending do while
}
}
+ 1
Yes. The excersize is actually edited from code coach task finding for 6 months remaining balance with rounding the result taking double type values into count.. Same excersize is added for calculating for 3 months with integer types.. They forgot to change the sample output, how ever they clearly added result, so it clear the confusion I think. But they should also correct the sample outputoutput as well..
Hope you are now cleared the task...!!!
0
Program need to accept single input of integer it's like Sample Input:
2000
And output you need to display is the result that is like Sample Output:
14580 // this is the only output you need to display.
Remaining other is the explanation given to you to understand how it going to compute as an algorithm for you..
So just output
System.out.println(balance); after the loop.
Remove all output statements inside the loop..
hope it clear now..
0
for an student it will be a very dificult excersize your system will only qualify the last output to put it as resolved, that is just What I see as something you can improve. Regards