942,779 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 17948
  • Java RSS
Feb 1st, 2009
0

Java Mortgage Calculator Program

Expand Post »
Hello Everyone!
I have a homework assignment due and I am having a problem with an compiling it to get an output.
This is my first and only Java class.

Can someone please tell me what I am doing wrong?
Thanks in advance.

Java Syntax (Toggle Plain Text)
  1. /*
  2. Programmer:Steve A. Massiah
  3. Date:01/29/09
  4. Course:PRG/420
  5. File: McBrideCR1.java
  6. Requestor:Dwain Hammer
  7. Request Description:Write the program in Java (without a graphical user interface) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term.
  8. Display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan.
  9. If the list would scroll off the screen, use loops to display a partial list, hesitate, and then display more of the list.
  10.  
  11.  */
  12.  
  13. import java.io.BufferedReader;
  14. import java.io.IOException;
  15. import java.io.InputStreamReader;
  16.  
  17. public class McBrideCR1 {
  18.  
  19. /** Creates a static mortgagecalculator */
  20. public int years;//define variables
  21. public double loanAmount;
  22. public double interestRate;
  23. public double monthlyPayment;
  24.  
  25. public void setYears(int inYears)//setter
  26. {
  27. years = inYears;
  28. }//end set years
  29.  
  30. public int getYears()//getter
  31. {
  32. return years;
  33. }//end get years
  34.  
  35. public void setLoanAmount(double inLoanAmount)//setter
  36. {
  37. loanAmount = inLoanAmount;
  38. }//end set loanAmount
  39.  
  40. public double getLoanAmount()//getter
  41. {
  42. return loanAmount;
  43. }//end get loanAmount
  44.  
  45. public void setInterestRate(double inInterestRate)//setter
  46. {
  47. interestRate = inInterestRate;
  48. }//end set interestRate
  49.  
  50. public double getInterestRate()//getter
  51. {
  52. return interestRate;
  53. }//end get interestrate
  54.  
  55. public void CalcMonthlyPayment() {
  56. monthlyPayment = loanAmount * Math.pow(1 + interestRate / 12, years * 12) * (interestRate / 12) / (Math.pow(1 + interestRate / 12, years * 12) - 1);
  57. }// Divide the yearly interest rate of 5.75% by 12 to get monthly ineterst rate
  58. // Multiply the number of years by 12 to get the number of months
  59. // Formula for monthly payment: monthlyPayment = [P((1+r)^n)*r]/[(1+r^n)-1], where r and n are calculated as above.
  60. // This calculation is taken from the following webpage:
  61. // http://www.dreamincode.net/
  62.  
  63. public String toString() {//strings are used to store text and variables
  64. return "Mortgage Information" + "n" + "Loan Amount: $" + loanAmount + "n" + "Interest Rate: " + interestRate + "%" + "n" + "Term: " + (years * 12) + " months" + "n" + "Monthly Payment: $" + (Math.round(monthlyPayment * 100.00) / 100.00);//Using the round to two decimal places
  65. }
  66.  
  67. public void schedule() {//print schedule and scroll
  68. System.out.println();
  69. System.out.println("Month " + "t" + "Amount " + "tt" + "Interest " + "t" + "Balance ");
  70. int counter = 1;
  71. double Balance, Interest;
  72. while (counter <= years * 12) {
  73. int scrollCounter = 0;
  74. while (scrollCounter < 30) {
  75. Balance = loanAmount * (1 + interestRate / 12) - monthlyPayment; //Calculation of Balance
  76. Interest = loanAmount * interestRate / 12; //Calculation of Interest
  77. //Now print using the round to two decimal places
  78. System.out.println("" + counter + "tt" + (Math.round(loanAmount * 100.00) / 100.00) + "tt" + (Math.round(Interest * 100.00) / 100.00) + "tt" + (Math.round(Balance * 100.00) / 100.00));
  79. loanAmount = Balance; //Set the Principal for next round to the Balance of previous month
  80. counter++;
  81. scrollCounter++;
  82. }
  83. System.out.println("Press Enter to contiune..");
  84. BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
  85. String str = "";
  86. try {
  87. str = br.readLine();
  88. } catch (IOException ioe) {
  89. System.out.println(ioe);
  90. }
  91. }
  92. }//end group
  93. }//closing bracket
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DJMASSIAH017 is offline Offline
4 posts
since Feb 2009
Feb 1st, 2009
0

Re: Java Mortgage Calculator Program

What errors do you get and at which lines. Post the errors you get.

Also if it runs what results do you get what you were expecting?

Also the tab character is this:
\t

System.out.println("aaa\tbbbbb")

and for new line:
\n
System.out.println("aaa\nbbbbb")

Try running the above just for testing
Last edited by javaAddict; Feb 1st, 2009 at 4:21 am.
Sponsor
Featured Poster
Reputation Points: 1005
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,256 posts
since Dec 2007
Feb 1st, 2009
0

Re: Java Mortgage Calculator Program

Okay...
worked on it a little bit and now I get no errors(using Textpad/BlueJ).

Still cannot get it to run.
Now I get :
Exception in thread "main" java.lang.NoSuchMethodError: main

I am lost on this being a noob and all.

The result is supposed to be what is listed in the comments,javaAddict.

I think the professor wants them listed in columns(like a group of four).

Lemme know what you think.
Thanks for the quick response, as well.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DJMASSIAH017 is offline Offline
4 posts
since Feb 2009
Feb 1st, 2009
0

Re: Java Mortgage Calculator Program

You need to write a main method in which you will execute the code you wrote. Right now you have only a class with methods. You need to call these methods inside the main
Sponsor
Featured Poster
Reputation Points: 1005
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,256 posts
since Dec 2007
Feb 1st, 2009
0

Re: Java Mortgage Calculator Program

OK...
I did what you told me and now I am getting an error on Line 93 in TextPad.
Quote ...
/*
Programmerteve A. Massiah
Date:01/29/09
CourseRG/420
File: McBrideCR1.java
Requestorwain Hammer
Request Description:Write the program in Java (without a graphical user interface) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term.
Display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan.
If the list would scroll off the screen, use loops to display a partial list, hesitate, and then display more of the list.

*/
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
public class McBrideCR1{

/** Creates a static mortgagecalculator */

public int years;//define variables
public double loanAmount;
public double interestRate;
public double monthlyPayment;
private BufferedReader key;

public void setYears(int inYears)//setter
{
years=inYears;
}//end set years

public int getYears()//getter
{
return years;
}//end get years

public void setLoanAmount(double inLoanAmount)//setter
{
loanAmount=inLoanAmount;
}//end set loanAmount

public double getLoanAmount()//getter
{
return loanAmount;
}//end get loanAmount

public void setInterestRate(double inInterestRate)//setter
{
interestRate=inInterestRate;
}//end set interestRate

public double getInterestRate()//getter
{
return interestRate;
}//end get interestrate

public void CalcMonthlyPayment()
{
monthlyPayment=loanAmount*Math.pow(1 + interestRate/12, years*12) * (interestRate/12)/(Math.pow(1 + interestRate/12, years*12) -1);
}//Divide the yearly interest rate of 5.75% by 12 to get monthly ineterst rate
// Multiply the number of years by 12 to get the number of months
// Formula for monthly payment: monthlyPayment = [P((1+r)^n)*r]/[(1+r^n)-1], where r and n are calculated as above.
// This calculation is taken from the following webpage:
//http://www.dreamincode.net/
public String toString(){//strings are used to store text and variables
return "Mortgage Information" + "n" + "Loan Amount: $" + loanAmount + "n" + "Interest Rate: " + interestRate + "%" + "n" + "Term: "
+ (years*12) + " months" + "n" + "Monthly Payment: $" + (Math.round(monthlyPayment*100.00)/100.00);//Using the round to two decimal places
}
public void schedule(){//print schedule and scroll
System.out.println();
System.out.println("Month " + "t" + "Amount " + "tt" + "Interest " + "t" + "Balance ");
int counter = 1;
double Balance, Interest;
while(counter <= years*12){
int scrollCounter = 0;
while(scrollCounter<30){
Balance = loanAmount*(1+interestRate/12) - monthlyPayment; //Calculation of Balance
Interest = loanAmount*interestRate/12; //Calculation of Interest
//Now print using the round to two decimal places
System.out.println(""+counter+"tt"+(Math.round(loanAmount*100.00)/100.00)+"tt"+(Math.round(Interest*100.00)/100.00)+"tt"+(Math.round(Balance*100.00)/100.00));
loanAmount = Balance; //Set the Principal for next round to the Balance of previous month
counter++;
scrollCounter++;
}
System.out.println("Press Enter to contiune..");
//BufferedReader enter key = new BufferedReader(new InputStreamReader(System.in), 1);
String str = "";

}//end group
}
}
}//closing bracket
}
}
java:93: class interface or enum expected
1 error
Tool completed with exit code 1

I am bleary eyed.
It is 4AM here in the states.

I dunno...
Maybe I will try agian later today.

Thanks, javaAddict.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DJMASSIAH017 is offline Offline
4 posts
since Feb 2009
Feb 1st, 2009
0

Re: Java Mortgage Calculator Program

I told you to write a main method in which you will call your other methods. You wrote this:

public class Main {
public class McBrideCR1{

The above doesn't mean anything. Surely this is not the first program you wrote. Check your notes. Writing a main method is the first thing you learn.
Sponsor
Featured Poster
Reputation Points: 1005
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,256 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: I need help with an if/else statement inside a for loop
Next Thread in Java Forum Timeline: two dimensional array temperature





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC