/* Assignment Week 3: McBride Financial Services Mortgage Payment Calculator Programmer: C. Peach Date: September 20, 2008 Filename: MortgageCalculator2.java Purpose: This project will calculate mortgage payment amounts. */ import java.io.*; import java.text.DecimalFormat; public class MortgageCalculator2 { public static void main(String[] args) throws IOException { // declare variables double orignialLoan = 200000; double newLoan = 200000; double interest = .0575; int months = 360; String str = ""; double payment; // print to display monitor System.out.println("\t McBride Mortgage Payment Calculator"); System.out.println(); System.out.println("\t $200,000.00 Loan"); System.out.println(); System.out.println("\t at 5.75% for 30 year term"); System.out.println(); DecimalFormat twoDigits = new DecimalFormat("$##,###.##");// Format how it will be displayed. // While Statement. while (count <= 360) { orignialLoan = newLoan; double interest = getInterest (Rate); // Interest rate for the month. double payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. double loanPayment = orignialLoan  newLoan; // Amount of monthly loan. double interestPayment = payment  loanPayment;// Amount of monthly interest. // Print to display moniter. System.out.println("The monthly payment on " + orignialLoan + "at 5.75% rate is " + twoDigits.format(payment)); System.out.println(); System.out.println("New Balance " + twoDigits.format(newLoan)); System.out.println("Loan Payment " + twoDigits.format(loanPayment)); System.out.println("Interest Payment " + twoDigits.format(interestPayment)); System.out.println(); System.out.println(); System.out.println("Continue (y or n): "); str = input.nextLine(); loop = count  1; { // End While } // end of main // Get Interest Method public static double getInterest(double interest) { double interest = interest / (12 * 100); return interest; } // End of Interest Method // Get Payment Method public static double getPayment (double Interest, double orignialLoan) { double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months)); return payment; } // End of Payment Method // Get New Loan Amount public static double getNewLoan (double Interest, double payment, double orignialLoan) { double NewLoan = orginialLoan * (1 + Interest)  payment; return NewLoan; } // End New Loan Amount } // end program
22 Replies  2320 Views  Last Post: 21 September 2008  10:17 AM
#1
Mortgage Calculator Help
Posted 20 September 2008  05:22 AM
Replies To: Mortgage Calculator Help
#2
Re: Mortgage Calculator Help
Posted 20 September 2008  05:46 AM
{ // End While
it should be }, yours is the wrong way.
double interest = getInterest (Rate); // Interest rate for the month. double payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. double loanPayment = orignialLoan  newLoan; // Amount of monthly loan. double interestPayment = payment  loanPayment;// Amount of monthly interest.
Some of these are already declared at the top, which means you dont need to put the datatype again, so double payment should just be payment. But make sure you declare all the variables you need at the top. for instance you havnt declared interestPayments at the top.
You never declare Rate and loanPayment. You have to just work your way through all your errors cos there are quite alot. Hope this gets you started
#3
Re: Mortgage Calculator Help
Posted 21 September 2008  12:49 AM
nick2price, on 20 Sep, 2008  05:46 AM, said:
{ // End While
it should be }, yours is the wrong way.
double interest = getInterest (Rate); // Interest rate for the month. double payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. double loanPayment = orignialLoan  newLoan; // Amount of monthly loan. double interestPayment = payment  loanPayment;// Amount of monthly interest.
Some of these are already declared at the top, which means you dont need to put the datatype again, so double payment should just be payment. But make sure you declare all the variables you need at the top. for instance you havnt declared interestPayments at the top.
You never declare Rate and loanPayment. You have to just work your way through all your errors cos there are quite alot. Hope this gets you started
Thank you for the help and I am getting somewhere. I am down from 20 errors to 6! I keep getting these 6 errors no matter what I change and I do not understand why.
These are the errors:
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:79: cannot find symbol
symbol : variable rate
location: class MortgageCalculator2
interest = rate / (12 * 100);
^
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:89: cannot find symbol
symbol : variable rate
location: class MortgageCalculator2
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
^
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:89: cannot find symbol
symbol : variable rate
location: class MortgageCalculator2
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
^
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:89: operator + cannot be applied to int,<any>
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
^
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:89: cannot find symbol
symbol : variable months
location: class MortgageCalculator2
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
^
C:\My Program Files\Assignment Programs Made Java\MortgageCalculator2.java:89: pow(double,double) in java.lang.Math cannot be applied to (<nulltype>,int)
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
^
6 errors
Tool completed with exit code 1
Here is my updated code...can someone explain these errors to me, I have been using this as an error reference but so many things are confusing right now! http://www.skylit.co...B.html#badcast
import java.io.*; import java.text.DecimalFormat; import java.util.Scanner; public class MortgageCalculator2 { public static void main(String[] args) throws IOException { // declare variables double orignialLoan = 200000; double newLoan = 200000; double interest = .0575; int months = 360; String str = ""; double payment; double rate = .0575; double loanPayment = 0; double interestPayment = 0; char loop = 'y'; // print to display monitor System.out.println("\t McBride Mortgage Payment Calculator"); System.out.println(); System.out.println("\t $200,000.00 Loan"); System.out.println(); System.out.println("\t at 5.75% for 30 year term"); Scanner input = new Scanner(System.in); System.out.println(); DecimalFormat twoDigits = new DecimalFormat("$##,###.##");// Format how it will be displayed. // While Statement. while (loop == 'y') { orignialLoan = newLoan; interest = getInterest (rate); // Interest rate for the month. payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. loanPayment = orignialLoan  newLoan; // Amount of monthly loan. interestPayment = payment  loanPayment;// Amount of monthly interest. // Print to display moniter. System.out.println("The monthly payment on " + orignialLoan + "at 5.75% rate is " + twoDigits.format(payment)); System.out.println(); System.out.println("New Balance " + twoDigits.format(newLoan)); System.out.println("Loan Payment " + twoDigits.format(loanPayment)); System.out.println("Interest Payment " + twoDigits.format(interestPayment)); System.out.println(); System.out.println(); System.out.println("Continue (y or n): "); str = input.nextLine(); loop = str.charAt(0); } // End While } // end of main // Get Interest Method public static double getInterest(double interest) { interest = rate / (12 * 100); return interest; } // End of Interest Method // Get Payment Method public static double getPayment (double interest, double orignialLoan) { double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months)); return payment; } // End of Payment Method // Get New Loan Amount public static double getNewLoan (double interest, double payment, double orignialLoan) { double newLoan = (orignialLoan * (1 + interest)  payment); return newLoan; } // End New Loan Amount } // end program
#4
Re: Mortgage Calculator Help
Posted 21 September 2008  04:34 AM
public static double getInterest(double interest)
{
interest = rate / (12 * 100);
return interest;
} // End of Interest Method
should be
public static double getInterest(double rate)
{
return rate / (12 * 100); //Is this calculation correct?
} // End of Interest Method
But then I think you have some miscalculations in your code that you may have to address later.
Anyways, errors 46 should disappear if you change:
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
to
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate), months));
At least this should get you onward.
This post has been edited by Gloin: 21 September 2008  04:36 AM
#5
Re: Mortgage Calculator Help
Posted 21 September 2008  05:09 AM
Gloin, on 21 Sep, 2008  04:34 AM, said:
public static double getInterest(double interest)
{
interest = rate / (12 * 100);
return interest;
} // End of Interest Method
should be
public static double getInterest(double rate)
{
return rate / (12 * 100); //Is this calculation correct?
} // End of Interest Method
But then I think you have some miscalculations in your code that you may have to address later.
Anyways, errors 46 should disappear if you change:
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months));
to
double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate), months));
At least this should get you onward.
I got that all cleared up now I am trying something else and I can not seem to figure it out to save my life. I am putting a counter in the program the problem is I have continue Y or N. well the program works the way i want but if you hit y it does what it is suppose to do...its when i hit N the program will not exit. Been playing with it for a couple of hours now. Any help will thank in advance!!
import java.io.*; import java.text.DecimalFormat; import java.util.Scanner; public class MortgageCalculator2 { static int months = 360; static double rate = .0575; public static void main(String[] args) throws IOException { // declare variables double orignialLoan = 200000; double newLoan = 200000; String str = ""; double payment; double loanPayment = 0; double interestPayment = 0; int i; // print to display monitor System.out.println("\t McBride Mortgage Payment Calculator"); System.out.println(); System.out.println("\t $200,000.00 Loan"); System.out.println(); System.out.println("\t at 5.75% for 30 year term"); Scanner input = new Scanner(System.in); System.out.println(); DecimalFormat twoDigits = new DecimalFormat("$##,###.##");// Format how it will be displayed. // For Statement. orignialLoan = newLoan; for (i = 1; i <= months; i ++) { double interest = getInterest (rate); // Interest rate for the month. payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. loanPayment = orignialLoan  newLoan; // Amount of monthly loan. interestPayment = payment  loanPayment;// Amount of monthly interest. // Print to display moniter. System.out.println("The monthly payment on " + twoDigits.format(orignialLoan) + " at 5.75% rate is " + twoDigits.format(payment)); System.out.println(); System.out.println("New Balance " + twoDigits.format(newLoan)); System.out.println("Loan Payment " + twoDigits.format(loanPayment)); System.out.println("Interest Payment " + twoDigits.format(interestPayment)); if (i % 3 == 0){ System.out.println("Continue (Y or N)"); str = input.nextLine(); if(input.equals("N")  input.equals("n")) { break; } } } // End For } // end of main // Get Interest Method public static double getInterest(double rate) { double interest = rate / (12 * 100); return interest; } // End of Interest Method // Get Payment Method public static double getPayment (double interest, double orignialLoan) { double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months)); return payment; } // End of Payment Method // Get New Loan Amount public static double getNewLoan (double interest, double payment, double orignialLoan) { double newLoan = orignialLoan * (1 + interest)  payment; return newLoan; } // End New Loan Amount } // end program
#6
Re: Mortgage Calculator Help
Posted 21 September 2008  05:16 AM
break;
for
System.exit(0);
#7
Re: Mortgage Calculator Help
Posted 21 September 2008  05:20 AM
#8
Re: Mortgage Calculator Help
Posted 21 September 2008  05:39 AM
Scanner input = new Scanner(System.in);
str = input.nextLine();
instead, write
str = input.next();
#9
Re: Mortgage Calculator Help
Posted 21 September 2008  06:11 AM
Gloin, on 21 Sep, 2008  05:39 AM, said:
Scanner input = new Scanner(System.in);
str = input.nextLine();
instead, write
str = input.next();
I am at a total loss now. It was running just fine and even before your last couple of post I have managed to screw the whole thing up grrrrrr. It will still compile just fine but somewhere within the logic I have managed to change something and I do not remember what!! Now it will not go back through the loop...and if you hit anything say Y or N or any key for that matter it just keeps repeating the same information grrrr it is not even doing the loop now. My eyes and my head is going crazy!! Here is my last coding that I now have:
import java.io.*; import java.text.DecimalFormat; import java.util.Scanner; public class MortgageCalculator2 { static int months = 360; static double rate = .0575; public static void main(String[] args) throws IOException { // declare variables double orignialLoan = 200000; double newLoan = 200000; String str = ""; double payment; double loanPayment = 0; double interestPayment = 0; int i; // print to display monitor System.out.println("\t McBride Mortgage Payment Calculator"); System.out.println(); System.out.println("\t $200,000.00 Loan"); System.out.println(); System.out.println("\t at 5.75% for 30 year term"); Scanner input = new Scanner(System.in); System.out.println(); DecimalFormat twoDigits = new DecimalFormat("$##,###.##");// Format how it will be displayed. // For Statement. orignialLoan = newLoan; for (i = 1; i <= months; i ++) { double interest = getInterest (rate); // Interest rate for the month. payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. loanPayment = orignialLoan  newLoan; // Amount of monthly loan. interestPayment = payment  loanPayment;// Amount of monthly interest. // Print to display moniter. System.out.println("The monthly payment on " + twoDigits.format(orignialLoan) + " at 5.75% rate is " + twoDigits.format(payment)); System.out.println(); System.out.println("New Balance " + twoDigits.format(newLoan)); System.out.println("Loan Payment " + twoDigits.format(loanPayment)); System.out.println("Interest Payment " + twoDigits.format(interestPayment)); if (i % 3 == 0){ System.out.println("Continue? (Y or N)"); str = input.next(); if(input.equals("N")  input.equals("n")) { break; } } } // End For } // end of main // Get Interest Method public static double getInterest(double rate) { double interest = rate / (12 * 100); return interest; } // End of Interest Method // Get Payment Method public static double getPayment (double interest, double orignialLoan) { double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months)); return payment; } // End of Payment Method // Get New Loan Amount public static double getNewLoan (double interest, double payment, double orignialLoan) { double newLoan = orignialLoan * (1 + interest)  payment; return newLoan; } // End New Loan Amount } // end program
#10
Re: Mortgage Calculator Help
Posted 21 September 2008  06:46 AM
#11
Re: Mortgage Calculator Help
Posted 21 September 2008  06:52 AM
#12
Re: Mortgage Calculator Help
Posted 21 September 2008  06:54 AM
nick2price, on 21 Sep, 2008  06:46 AM, said:
I am still here I will have a look at it.....i may change back to the while loop!! I hate to give up but I have been on this all night and it was due yesterday now my eyes are way passed crossed!! But I am still trying to fix it. Shoot I was so happy to get it working this far and I had everything working but stupid me wanted it to show a few and break then when you hit the Y it would show a few more and so on........
#13
Re: Mortgage Calculator Help
Posted 21 September 2008  07:19 AM
cpeachy1223, on 21 Sep, 2008  06:54 AM, said:
nick2price, on 21 Sep, 2008  06:46 AM, said:
I am still here I will have a look at it.....i may change back to the while loop!! I hate to give up but I have been on this all night and it was due yesterday now my eyes are way passed crossed!! But I am still trying to fix it. Shoot I was so happy to get it working this far and I had everything working but stupid me wanted it to show a few and break then when you hit the Y it would show a few more and so on........
********Update to all that have been trying to help me figure this out********
I have managed to get it to go back through the loop it is now subtracting the payments made again!!
Now I am just left with getting my counter working right in that it will
respond the right way to the Continue Y or N question.
#14
Re: Mortgage Calculator Help
Posted 21 September 2008  09:14 AM
/* Assignment Week 3: McBride Financial Services Mortgage Payment Calculator Programmer: C. Peach Date: September 20, 2008 Filename: MortgageCalculator2.java Purpose: This project will calculate mortgage payment amounts. */ import java.io.*; import java.text.DecimalFormat; import java.util.Scanner; public class MortgageCalculator2 { static int months = 360; static double rate = .0575; public static void main(String[] args) throws IOException { // declare variables double orignialLoan = 200000; double newLoan = 200000; String str = ""; double payment; double loanPayment = 0; double interestPayment = 0; int i; // print to display monitor System.out.println("\t McBride Mortgage Payment Calculator"); System.out.println(); System.out.println("\t $200,000.00 Loan"); System.out.println(); System.out.println("\t at 5.75% for 30 year term"); Scanner input = new Scanner(System.in); System.out.println(); DecimalFormat twoDigits = new DecimalFormat("$##,###.##");// Format how it will be displayed. // For Statement. for (i = 1; i <= months; i ++) { orignialLoan = newLoan; double interest = getInterest (rate); // Interest rate for the month. payment = getPayment (interest, orignialLoan); // Payment per month. newLoan = getNewLoan (interest, payment, orignialLoan); // Balance after payment. loanPayment = orignialLoan  newLoan; // Amount of monthly loan. interestPayment = payment  loanPayment;// Amount of monthly interest. // Print to display moniter. System.out.println("The monthly payment on " + twoDigits.format(orignialLoan) + " at 5.75% rate is " + twoDigits.format(payment)); System.out.println(); System.out.println("New Balance " + twoDigits.format(newLoan)); System.out.println("Loan Payment " + twoDigits.format(loanPayment)); System.out.println("Interest Payment " + twoDigits.format(interestPayment)); if (i % 3 == 0){ System.out.println("Continue? (Y or N)"); str = input.nextLine(); if(input.equals("N")  input.equals("n")) { System.exit(0); } else return;{ } } } // End For } // end of main // Get Interest Method public static double getInterest(double rate) { double interest = rate / (12 * 100); return interest; } // End of Interest Method // Get Payment Method public static double getPayment (double interest, double orignialLoan) { double payment = (orignialLoan * getInterest(rate)) / (1  Math.pow(1 + getInterest(rate),  months)); return payment; } // End of Payment Method // Get New Loan Amount public static double getNewLoan (double interest, double payment, double orignialLoan) { double newLoan = orignialLoan * (1 + interest)  payment; return newLoan; } // End New Loan Amount } // end program
#15
Re: Mortgage Calculator Help
Posted 21 September 2008  09:24 AM
If the user replies something else than N or n you should just continue not "return"
if (i % 3 == 0){ System.out.println("Continue? (Y or N)"); str = input.nextLine(); if(str.equals("N")  str.equals("n")) System.exit(0); }
