Results 1 to 4 of 4
  1. #1
    SolidCobra is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default Difficulty in finding the right algorithm

    The assignment problem below ask me to calculate the number of months it will take to pay off the loan and the total amount of interest paid over the life of the loan. I'm having trouble trying to find the right algorithm for the monthly payments. Could you please take a look at my code and see what I'm doing wrong? I'm using TextPad, btw.



    You have just purchased a stereo system that cost $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1000 in interest. That is $15 interest. So the remaining $35 is deducted from your debt, which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence you can deduct $35.52 (which is $50 - $14.48) from the amount you owe. Write a program that will tell you how many months it will take you to pay off the loan, as well as the total amount of interest paid over the life of the loan. Use a loop to calculate the amount of interest and the size of the debt after each month. (Your final program need not output the monthly amount of interest paid and remaining debt, but you may want to write a preliminary version of the program that does output these values.) Use a variable to count the number of loop iterations, and hence the number of months until the debt is zero. You may want to use other variables as well. The last payment may be less than the $50 if the debt is small, but do not forget the interest. If you owe $50, then your monthly payment of $50 will not pay off your debt, although it will come close. One month's interest on $50 is only 75 cents.


    Here's my code

    Java Code:
    import java.util.Scanner;
    
     public class StereoSystem
     {
    
         public static void main (String [] args)
         {
    
             Scanner in = new Scanner (System.in);
    
             System.out.print ("Enter the amount of the loan: $");
             double principal = in.nextDouble ();
    
    
             System.out.print ("Enter the monthly payments: ");
             double MonthlyPayments = in.nextDouble ();
    
    
             System.out.print ("Enter the interest rate: ");
             double interestRate = in.nextDouble () / 100.0;
    
    
             double sum = 0;
             for (int n = 1;  n <= years;  n++)
                 sum += (1.0 - (n - 1.0) / years);
    
    
             double totalInterest = principal * interestRate * sum;
    
    
             double numberOfMonths = 
             (principal + totalInterest) / ( monthly payments);
    
    
             System.out.printf ("The number of months it will take to pay off the loan is " + );
    
         }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You're using the wrong equations for amortizing a loan. Have a look here: Amortization calculator - Wikipedia, the free encyclopedia

  3. #3
    Join Date
    Oct 2008
    Posts
    68
    Rep Power
    0

    Default

    I would suggest u to do some debugging on same and understand it urself...instead of people here trying out....assignments purpose must be that only :)

  4. #4
    SolidCobra is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    My uncle's friend who happens to be a CS major is helping me with my project so I guess you can now close my thread as I won't be needing any help from this forum.

Similar Threads

  1. O(log n) algorithm help !!!!!!
    By itseeker87 in forum New To Java
    Replies: 8
    Last Post: 09-09-2008, 05:12 PM
  2. Replies: 0
    Last Post: 04-12-2008, 08:38 PM
  3. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 10:26 PM
  4. Help me with this algorithm
    By Marcus in forum Advanced Java
    Replies: 3
    Last Post: 07-02-2007, 01:30 PM
  5. Help with Algorithm
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •