|
-
November 26th, 2014, 02:43 PM
#1
Writing Java from pseudocode: interest payments
calculate how long it would take to pay off a loan of 500 pounds if there was 10% interest monthly, and 100 pounds was paid each month. This code is in a pseudocode, but I can't figure out how to write it in Java, I'm really new to Java and need some assistance, I appreciate any help that is give, thanks!
Code:
set months = 1
set balance = 500
set totalpaid = 0;
while balance > 100
balance = balance - 100;
set interest = balance * 0.1
balance = balance + interest
totalpaid = totalpaid + 100
months = months + 1
endwhile
totalpaid = totalpaid+balance
display "You paid "+totalpaid
display "It took you "+months+" months"
-
December 15th, 2014, 08:06 PM
#2
Re: Writing Java from pseudocode: interest payments
Just straightforward.
Code:
public class Main {
public static void main(String[] args){
int months = 1;
double balance = 500;
double totalpaid = 0;
double interest = 0;
while(balance>100){
balance = balance - 100;
interest = balance * 0.1;
balance = balance + interest;
totalpaid = totalpaid + 100;
months = months + 1;
}
totalpaid = totalpaid + balance;
System.out.println("You paid " + totalpaid);
System.out.println("It took you "+ months +" months");
}
}
Last edited by camimi; December 15th, 2014 at 09:35 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|