Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Zigster

Thread: Homework assignment: NEED HELP Please.

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Homework assignment: NEED HELP Please.

    So my computer programming class has this for a project this week:

    Loan Payoff Project

    You have just purchased a stereo that cost $1,000 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 $1,000 in interest. That is $15 in 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 tells 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. Inside a loop you will need to calculate the amount of interest and the size of the remaining debt after each month. Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. The last payment may be less than $50 if the debt is small, but do not forget the interest. If you owe $50, your monthly payment of $50 will not pay off your debt, althought it will come close. One month’s interest on $50 is only 75 cents.

    I have some of it done, but I'm having problems running the program. If someone could please advice me on what I am doing wrong that would be very much appreciated and very helpful. Thank you.


    Java Code:
    public class LoanPayoffProject
    {
    	public static void main(String[] args)
    	{
    		double debt = 1000;
    		double payment = 50;
    		double interestRate = 0.015;
    		double interest = 0;
    		double totalInterest = 0;
    		double principal = 0;
    		int monthCounter = 0;
    		while (debt > 0);
    		{
    			interest = (debt * interestRate);
    			principal = ((interest - payment) + debt);
    			totalInterest = (totalInterest + interest);
    			principal = (payment - interest);
    			debt = (debt - payment);
    			monthCounter++;
    			System.out.println(Helper.showCurrency(totalInterest));
    			System.out.println(monthCounter);
    			System.out.println(Helper.showCurrency(principal));
    			{
    				if (debt < payment) payment = debt + interest;
    				{
    					principal = payment - interest;
    					debt = debt - principal;
    					{
    						System.out.println(Helper.showCurrency(totalInterest));
    						System.out.println(monthCounter);
    						System.out.println(Helper.showCurrency(principal));
    					}
    				}
    			}
    		}	
    	}
    }

  2. #2
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Homework assignment: NEED HELP Please.

    What errors are you getting?

    I noticed one problem. Remove the semicolon after while (debt > 0).

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Homework assignment: NEED HELP Please.

    Thank you, I have actually just figured the problem and fixed it. ^_^

  4. #4
    Zigster is offline Member
    Join Date
    Apr 2012
    Posts
    74
    Rep Power
    0

    Default Re: Homework assignment: NEED HELP Please.

    You should post what the problem was, and how you fixed, so others like myself might learn.
    DarrylBurke likes this.

  5. #5
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: Homework assignment: NEED HELP Please.

    So here is the final result I got and it runs totally perfectly. If you compare to the original you can see the changes and bugs I worked out.

    Java Code:
    public class LoanPayoff
    {
    	public static void main(String[] args)
    	{
    		double debt = 1000;
    		double payment = 50;
    		double interestRate = 0.015;
    		double interest = 0;
    		double totalInterest = 0;
    		double principal = 0;
    		int monthCounter = 0;
    		
    		while (debt > 0)
    		{
    			interest = (debt * interestRate);
    			totalInterest = (totalInterest + interest);
    			if (debt < payment) payment = debt + interest;
    			principal = (payment - interest);
    			debt = (debt - principal);
    			monthCounter++;
    		}
    		System.out.println("Total Interest is: " + Helper.showCurrency(totalInterest));
    		System.out.println("Months to pay off loan is: " + monthCounter + " months");
    	
    	}
    }

Similar Threads

  1. Homework Assignment, Need some help
    By xdrazkalnytex in forum New To Java
    Replies: 3
    Last Post: 04-28-2012, 01:56 AM
  2. Homework Assignment, Need some help
    By xdrazkalnytex in forum New To Java
    Replies: 17
    Last Post: 04-11-2012, 06:56 PM
  3. Replies: 7
    Last Post: 02-29-2012, 02:15 PM
  4. Calculator Program HELP NEEDED FAST! Homework assignment
    By SteroidalPsycho in forum New To Java
    Replies: 3
    Last Post: 03-05-2009, 05:02 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
  •