CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2014
    Posts
    1

    Exclamation 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"

  2. #2
    Join Date
    Dec 2014
    Posts
    8

    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
  •  





Click Here to Expand Forum to Full Width

Featured