Results 1 to 15 of 15
Thread: Mortgage Calculator
- 01-21-2011, 05:54 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Mortgage Calculator
Getting error on compiling. Need some assistance on where I went wrong. Thanks
[CODE]
public void onButtonChart()
{
Chart = new Chart((int) (loanTerm / 12)); // Create Instance of Class
System.out.println("" + loanTerm);
}
// Display Methods to Print Values for Morgage Calculator
public void assignLoanAmount(double loanAmount)
{
principalBalance = loanAmount;
}
public void assignLoanRate(double interestAmount)
{
loanRate = interestAmount;
}
public void assignLoanTerm(double termAmount)
{
loanTerm = termAmount;
}
public double getAssignLoanAmount()
{
return principalBalance;
}
public double getAssignLoanRate()
{
return loanRate ;
}
public double getAssignLoanTerm()
{
return loanTerm;
}
public void calculateMonthlyPayment()
{
monthlyRate = (loanRate / 100) / 12;
monthlyPayment = principalBalance *((monthlyRate*(Math.pow((1 + monthlyRate),loanTerm)))
/(Math.pow((1 + monthlyRate),loanTerm)-1));
}
public void calculateMonthlyInterest()
{
monthlyInterestRate = (loanRate / 12) / 100;
interestMonthly = principalBalance * monthlyInterestRate;
}
public void calculateMonthlyPrinciple()
{
monthlyPrinciple = monthlyPayment - interestMonthly;
}
public void calculateLoanBalance()
{
loanBalance = principalBalance - monthlyPrinciple;
}
public void calculateNewBalance()
{
newBalance = loanBalance - monthlyPrinciple;
}
public void monthlyLoanAmount()
{
result.append("Month\tLoanBalance\tInterest Paid\n");
double newloanTerm = loanTerm;
while (newloanTerm>0)
{
double loanMonths = loanTerm-newloanTerm;
double newMonthlyBalance = principalBalance *((Math.pow((1 + monthlyInterestRate),loanTerm))
-(Math.pow((1 + monthlyInterestRate),loanMonths)))/(Math.pow((1 + monthlyInterestRate),loanTerm)-1);
double monthlyamountInterest = newMonthlyBalance * monthlyInterestRate;
result.append("" + Math.round(newloanTerm) + "\t" + Dollar.format(newMonthlyBalance)
+ "\t" + Dollar.format(monthlyamountInterest) + "\n");
newloanTerm -= 1;
}
}
[CODE]
ERROR:
308 : cannot find symbol symbol : variable Chart location: class MortgageCalculatorWK4 Chart = new Chart((int) (loanTerm / 12));
308 : cannot find symbol symbol : class Chart location: class MortgageCalculatorWK4 Chart = new Chart((int) (loanTerm / 12));
-
Please show the actual error message, not your abbreviation of it, and please correct your code tags so we can read your code. The bottom tag should be [/code] not [code].
-
Also, where is your Chart class that you are trying to use? Can you post the code for it (with tags) as well?
- 01-21-2011, 06:00 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Error
I have the error posted at the bottom of the post. That is the messag in its entirity. Sorry out the tag, missed the /.
- 01-21-2011, 06:04 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Here is the code.
Java Code:import java.awt.BorderLayout; // Code to Import and Provide Layout of Window import java.awt.GridLayout; // Code to Import the Layout in Grid Format import java.awt.event.ActionEvent; // Code to Import Action import java.awt.event.ActionListener; // Code to Import Listener for Action import javax.swing.JButton; // Code to Import Use of Buttons import javax.swing.JFrame; // Code to Import Use of Frame import javax.swing.JLabel; // Code to Import Use of Label import javax.swing.JPanel; // Code to Import Use of Panel import javax.swing.JTextField; // Code to Import Use of Text Field import javax.swing.JTextArea; // Code to Import Use of Text Area import javax.swing.JScrollPane; // Code to Import Scroll Pane import javax.swing.JComboBox; // Code to Import JCombo Box import java.text.DecimalFormat; // Code to Import Decimal Format import javax.swing.ButtonGroup; // Code to Import Button Group import javax.swing.JOptionPane; // Code to Import Option Dialog Box import java.awt.Dimension; // Code to Import Dimension Class import java.io.*; // Code to Import ALL classes of input and output import javax.swing.JCheckBox; // Code to Import CheckBox // Create Mortgage Payment Class public class MortgageCalculatorWK4 extends JFrame { DecimalFormat Dollar = new DecimalFormat("$###,###.00"); // Beginning of Main public static void main(String[] args) { MortgageCalculatorWK4 newloan = new MortgageCalculatorWK4(); // Create Instance of Class } // Declare Variables and Values private double principalBalance; // Amount of Loan private double loanTerm; // Term of Loan private double loanRate; // Interest Rate of Loan private double monthlyRate; // Amount of Monthly Interest private double monthlyPayment; // Amount of Monthly Payment private double monthlyInterestRate; // Amount of Monthly Interest Rate private double interestMonthly; // Amount of Monthly Interest private double monthlyPrinciple; // Amount of Monthly Principle private double loanBalance; // Balance of Loan double newBalance; // New Monthly Balance of Loan private static int numberOfLinesGenerated = 1; // GUI elements to Display Current Information private JLabel labelPrincipal = new JLabel(" Mortgage Principal : "); private JTextField txtPrincipal = new JTextField(10); private JLabel labelYears = new JLabel(" Term : "); private JTextField txtYears = new JTextField(10); private JLabel labelRate = new JLabel(" Interest Rate : "); private JTextField txtRate = new JTextField(10); private JCheckBox buttonEnterValue = new JCheckBox("Enter Value"); private JCheckBox buttonSelectValue = new JCheckBox("Select Value"); private ButtonGroup buttongroup = new ButtonGroup(); private JTextArea result = new JTextArea(10, 20); JScrollPane Result = new JScrollPane(result); private JButton buttonCalc = new JButton("Calculate"); private JButton buttonClear = new JButton("Clear"); private JButton buttonNext = new JButton("Next"); private JButton buttonExit = new JButton("Exit"); private JButton buttonChart = new JButton("Chart"); private JPanel panel = new JPanel(); private JPanel nextButtonPanel = new JPanel(); JPanel pane = new JPanel(new BorderLayout()); String[] loanPlan = {"Select Loan", "7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"}; //Array for loan plan private JLabel labelPlan = new JLabel(" Mortgage Plan : "); private JComboBox comboBox = new JComboBox(loanPlan); // Create Container for Information public MortgageCalculatorWK4() { buttonCalc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onButtonCalculate(); } }); buttonClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onButtonReset(); } }); buttonExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); buttonChart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onButtonChart(); } }); panel.setLayout(new GridLayout(5, 2,3,3)); panel.add(labelPrincipal); panel.add(txtPrincipal); buttonEnterValue.setText("Get Values OR "); buttonSelectValue.setText("Select Values "); buttongroup.add(buttonEnterValue); buttonEnterValue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonEnterValueActionPerformed(evt); } }); buttonEnterValue.setSelected(true); buttongroup.add(buttonSelectValue); buttonSelectValue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonSelectValueActionPerformed(evt); } }); panel.add(buttonEnterValue); panel.add(buttonSelectValue); panel.add(labelYears); panel.add(txtYears); panel.add(labelRate); panel.add(txtRate); panel.add(buttonCalc); panel.add(buttonClear); nextButtonPanel.add(buttonChart); nextButtonPanel.add(buttonExit); final Dimension d = new Dimension(200, 200); setLayout(new BorderLayout()); add(panel, BorderLayout.NORTH); pane.add(nextButtonPanel, BorderLayout.NORTH); pane.add(Result, BorderLayout.SOUTH); buttonExit.setEnabled(false); buttonChart.setEnabled(false); add(pane, BorderLayout.SOUTH); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE ); setResizable(false); setTitle("Mortgage Calculator"); setVisible(true); } public void buttonEnterValueActionPerformed(ActionEvent evt) { if(buttonEnterValue.isSelected()){ panel.removeAll(); panel.add(labelPrincipal); panel.add(txtPrincipal); panel.add(buttonEnterValue); panel.add(buttonSelectValue); panel.add(labelYears); panel.add(txtYears); panel.add(labelRate); panel.add(txtRate); panel.add(buttonCalc); panel.add(buttonClear); setVisible(true); } } public void buttonSelectValueActionPerformed(ActionEvent evt) { if(buttonSelectValue.isSelected()){ panel.removeAll(); panel.add(labelPrincipal); panel.add(txtPrincipal); panel.add(buttonEnterValue); panel.add(buttonSelectValue); panel.add(labelPlan); panel.add(comboBox); panel.add(buttonCalc); panel.add(buttonClear); setVisible(true); } } // Calculate Information public void onButtonCalculate() { double loanAmt = Double.parseDouble(txtPrincipal.getText()); assignLoanAmount(loanAmt); // Assign Amount of Loan if(buttonEnterValue.isSelected()) { try { StreamTokenizer tokenizer = new StreamTokenizer(new FileReader("loanData.txt")); while(tokenizer.nextToken()!= StreamTokenizer.TT_EOF) { if(tokenizer.lineno() == numberOfLinesGenerated) { if(tokenizer.ttype == StreamTokenizer.TT_NUMBER) { assignLoanTerm(tokenizer.nval * 12); } txtYears.setText("" + tokenizer.nval); tokenizer.nextToken(); if(tokenizer.ttype == StreamTokenizer.TT_NUMBER) { assignLoanRate(tokenizer.nval); } txtRate.setText("" + tokenizer.nval); break; } System.out.println (tokenizer.lineno()); } }catch (Exception addException){//Catch exception if any JOptionPane.showMessageDialog(null, "Error While reading Loandata file\n" + addException); } } else { String str = (String)comboBox.getSelectedItem(); if(str.equals("7 years at 5.35%")) { assignLoanRate(5.35); assignLoanTerm(7 * 12); } else if(str.equals("15 years at 5.5%")) { assignLoanRate(5.5); assignLoanTerm(15 * 12); } else if(str.equals("30 years at 5.75%")) { assignLoanRate(5.75); assignLoanTerm(30 * 12); } } calculateMonthlyPayment(); // Calculate Monthly Payment of Loan calculateMonthlyInterest(); // Calculate Monthly Interest on Loan calculateMonthlyPrinciple(); // Calculate Monthly Principle of Payment calculateLoanBalance(); // Calculate Loan Balance calculateNewBalance(); // Calculate New Balance Each Month displayAmounts(); // Display All Amounts monthlyLoanAmount(); monthlyBalanceInterest(getAssignLoanAmount(), getAssignLoanTerm(), getAssignLoanRate()); ++ numberOfLinesGenerated; if(numberOfLinesGenerated > 4) { numberOfLinesGenerated = 1; } buttonCalc.setEnabled(true); buttonClear.setEnabled(true); buttonExit.setEnabled(true); buttonNext.setEnabled(true); buttonChart.setEnabled(true); } // Information for Button public void onButtonReset() { txtPrincipal.setText(""); txtYears.setText(""); txtRate.setText(""); result.setText(""); } public void onButtonChart() { Chart = new Chart((int) (loanTerm / 12)); // Create Instance of Class System.out.println("" + loanTerm); } // Display Methods to Print Values for Morgage Calculator public void assignLoanAmount(double loanAmount) { principalBalance = loanAmount; } public void assignLoanRate(double interestAmount) { loanRate = interestAmount; } public void assignLoanTerm(double termAmount) { loanTerm = termAmount; } public double getAssignLoanAmount() { return principalBalance; } public double getAssignLoanRate() { return loanRate ; } public double getAssignLoanTerm() { return loanTerm; } public void calculateMonthlyPayment() { monthlyRate = (loanRate / 100) / 12; monthlyPayment = principalBalance *((monthlyRate*(Math.pow((1 + monthlyRate),loanTerm))) /(Math.pow((1 + monthlyRate),loanTerm)-1)); } public void calculateMonthlyInterest() { monthlyInterestRate = (loanRate / 12) / 100; interestMonthly = principalBalance * monthlyInterestRate; } public void calculateMonthlyPrinciple() { monthlyPrinciple = monthlyPayment - interestMonthly; } public void calculateLoanBalance() { loanBalance = principalBalance - monthlyPrinciple; } public void calculateNewBalance() { newBalance = loanBalance - monthlyPrinciple; } public void monthlyLoanAmount() { result.append("Month\tLoanBalance\tInterest Paid\n"); double newloanTerm = loanTerm; while (newloanTerm>0) { double loanMonths = loanTerm-newloanTerm; double newMonthlyBalance = principalBalance *((Math.pow((1 + monthlyInterestRate),loanTerm)) -(Math.pow((1 + monthlyInterestRate),loanMonths)))/(Math.pow((1 + monthlyInterestRate),loanTerm)-1); double monthlyamountInterest = newMonthlyBalance * monthlyInterestRate; result.append("" + Math.round(newloanTerm) + "\t" + Dollar.format(newMonthlyBalance) + "\t" + Dollar.format(monthlyamountInterest) + "\n"); newloanTerm -= 1; } } public void monthlyBalanceInterest(double loan, double term, double interestRate) { DecimalFormat df = new DecimalFormat("$###,###.00"); // Format Decimal Point double monthlyRate = (interestRate/(12*100)); // Get Monthly Interest Rate // Calculate Discount Factor double discountFactor = (Math.pow((1 + monthlyRate), term) -1) / (monthlyRate * Math.pow((1 + monthlyRate), term)); double payment1 = loan / discountFactor; // Calculate Monthly Payment // Display Program Results result.append("\nLoan Amount = " + df.format(loan)); result.append("\nInterest Rate = " + interestRate + "%"); result.append("\nLength of Loan = " + Math.round(term/12) +" years"); result.append("\nMonthly Payment = " + df.format(payment1) + "\n"); } public void displayAmounts() { System.out.println("Loan Amount = " + Dollar.format(principalBalance)); // Show Original Loan Amount System.out.println("Interest Rate = " + loanRate + "%"); // Show Interest Rate System.out.println("Length of Loan = " + Math.round(loanTerm) + " months"); // Show Length of Loan System.out.println("Monthly Payment = " + Dollar.format(monthlyPayment)); // Show Monthly Payment } }
- 01-21-2011, 07:15 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
You're trying to use a variable named 'Chart' but you never defined it anywhere. Your compiler whines about that. b.t.w. Chart seems to be a class; it is not a wise thing to do to name a variable identical to a class name; there's a naming convention, stick to it.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-21-2011, 07:46 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Missing It
Thanks Jos. Can you give me some guidance? I am completely missing it.
-
It's more than that. It looks like you're trying to use a class named Chart but Java can't find it. That's why I asked for your code for this class. Do you have it?
- 01-21-2011, 10:02 PM #9
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Here is what I changed; I created a variable private double chart.
double chart = ((int) (loanTerm / 12)); // Create Instance of Class
System.out.println("" + loanTerm);
Whenever I try and enter in the data manually, I get an error;
java.io.FileNotFoundException:loanData.txt(The system cannot find the file specified).
I have it declared above in the code. How do I get the manual entries to work when I hit calculate? Thanks
-
You never answered my questions about the "Chart" class. Why try to assist if only to be ignored?
- 01-21-2011, 10:21 PM #11
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
I don't have the code for the class. Which is why I was having a problem in the first place and am very happy you pointed that out. I am very new to this and am learning on the fly. I didnt realize I created the class until you pointed it out. I thought it was looing for a vaiable that I thought I had declared but was wrong. I figured out some of it from yourlast post. I appreciate all of your help. I appologize, I am not trying to ignor you. I am trying to fix the issues as I am reading and posting in the forum.
-
Your questions are somewhat simplistic -- nothing wrong with that, as we have to start somewhere -- but the code is complex, very complex. I need an honest answer from you -- is this your code? Did you create this from scratch? Or are you trying to "borrow" code from the internet, such as from here?
If so, this really isn't a good idea and will bite you in the end. Also, you should be up front with us about this type of stuff from the start.
- 01-21-2011, 10:31 PM #13
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Bits and pieces are from the internet and no it is not from here. Some of the infromation i am trying to use from te previous program that I wrote.
-
On analysis of code in the net, I think we can safely assume that > 95% of your code has been borrowed. Do yourself a favor and get rid of all the borrowed code, as otherwise all you'll create will be frankencode, and you'll understand very little of it or our attempts at help. Luck.
Last edited by Fubarable; 01-21-2011 at 10:38 PM.
- 01-21-2011, 10:53 PM #15
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
I've made this rant before and I'll make it again... don't ever copy and paste code -- always type it into your editor. Whatever reason you think you have for wanting to copy-and-paste source code, I have a better reason why you shouldn't.
But I'm bad at typing, and if I try to type it all in, I'll make mistakes. You need to get better at typing if you're going to be a programmer, and this is a great opportunity to get some practice.
But it's too long and complicated. Then maybe it belongs in a library rather than directly in this code file. But either way, you need to type it yourself and be sure that you understand every variable, every operator, every method. If it's really that long and complicated, then chances are you will want to change it someday, and when you do, it won't be good to have copies of it floating around in a bunch of different source files. It should be in one place: in a library.
But I don't have time to type it in myself. If you have time to read it, you have time to type it. And if you don't have time to read it, then it doesn't belong in your project. Code you paste into your project and don't know and understand thoroughly will cost you much much more time than code you've typed yourself.
-Gary-
Similar Threads
-
Calculator
By Moshe22 in forum New To JavaReplies: 8Last Post: 01-17-2011, 05:29 AM -
Mortgage Calculator
By pablo2002 in forum Java AppletsReplies: 3Last Post: 09-25-2010, 10:34 PM -
mortgage calculator help
By kalibballer in forum New To JavaReplies: 1Last Post: 03-26-2009, 11:35 AM -
Calculator help.
By madkidd02 in forum New To JavaReplies: 2Last Post: 10-25-2008, 07:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks