Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Help coderanch get a
new server
by contributing to the
fundraiser
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Beginning Java
One error in code..not understanding what it tells me. Code works it is on line 55.
LeeAnne Murphy
Greenhorn
Posts: 18
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package wk4calcjp2; /** * * @author LeeAnne Murphy * Java Programming 2/ PRG 421 * Due Date August 29, 2011 * Week 4 - SR-mf-003 Change Request #6 * Write the program in Java (with a graphical user interface) so that it will allow * the user to select which way they want to calculate a mortgage: by input of the * amount of the mortgage, the term of the mortgage, and the interest rate * of the mortgage payment or by input of the amount of a mortgage and then select * from a menu of mortgage loans: * - 7 year at 5.35% * - 15 year at 5.5 % * - 30 year at 5.75% * In either case, display the mortgage payment amount and then, list the loan balance * and interest paid for each payment over the term of the loan. Allow the user to loop * back and enter a new amount and make a new selection, or quit. * Insert comments in the program to document the program. */ 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.BorderFactory; // Code to Import Border import javax.swing.ButtonGroup; // Code to Import Button Group import javax.swing.JCheckBox; // Create Mortgage Payment Class public class Wk4calcjp2 extends JFrame { DecimalFormat Dollar = new DecimalFormat("$###,###.00"); // Beginning of Main public static void main(String[] args) { [b]Wk4calcjp2 newloan = new Wk4calcjp2()); [/b] // Create Instance of Class } // End main // 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 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 // GUI elements to Display Current Information private JLabel labelPrincipal = new JLabel(" Mortgage Principal : "); private JTextField txtPrincipal = new JTextField(10); private JLabel labelYears = new JLabel(" Mortgage Time In Years : "); private JTextField txtYears = new JTextField(10); private JLabel labelRate = new JLabel(" Amount Interest Rate : "); private JTextField txtRate = new JTextField(10); private JCheckBox buttonEnterValue = new JCheckBox("Enter Value"); private JCheckBox buttonselectValue = new JCheckBox("Select Value"); private ButtonGroup group = new ButtonGroup(); private JTextArea result = new JTextArea(10, 20); private JScrollPane scrollResult = new JScrollPane(result); private JButton buttonCalc = new JButton("Calculate"); private JButton buttonClear = new JButton("Clear"); private JButton buttonExit = new JButton("Exit"); private JPanel panel = new JPanel(); private String loanPlan[] = {"Select Loan", "7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"}; private JLabel labelPlan = new JLabel(" Mortgage Plan : "); private JComboBox comboBox = new JComboBox(loanPlan); /** * @param args the command line arguments */ // Create Container for Information public Wk4calcjp2() { buttonCalc.addActionListener(new ActionListener() // Adds an action listener to the calc button. The action listener will be called if button is selected. { public void actionPerformed(ActionEvent e) { onButtonCalculate(); // Calculates information when clicked } }); buttonClear.addActionListener(new ActionListener() // Adds an action listener to the clear button. The action listener will be called if button is selected. { public void actionPerformed(ActionEvent e) { onButtonClear(); // Clears information when clicked } }); //Declares button to clear (reset) the data buttonExit.addActionListener(new ActionListener() // Adds an action listener to the exit button. The action listener will be called if button is selected. { public void actionPerformed(ActionEvent e) { onButtonExit(); //Exits the program when clicked } }); panel.setLayout(new GridLayout(6, 4, 6, 6)); panel.add(labelPrincipal); panel.add(txtPrincipal); buttonEnterValue.setText("Enter Values OR "); //Checkbox selection fpr user entry buttonselectValue.setText("Select Values "); // Checkbox selection for user to select values group.add(buttonEnterValue); //Adds a button to a radio button group. buttonEnterValue.addActionListener(new ActionListener() { // Adds an action listener to the radio button. The action listener will be called if button is selected. public void actionPerformed(ActionEvent e) { buttonEnterValuesActionPerformed(e); } }); buttonEnterValue.setSelected(true); // Sets selected status of a radio button to true group.add(buttonselectValue); // Adds a button to a radio button group. buttonselectValue.addActionListener(new ActionListener() { // Adds an action listener to the radio button. The action listener will be called if button is selected. public void actionPerformed(ActionEvent e) { buttonselectValuesActionPerformed(e); } }); panel.add(buttonEnterValue); panel.add(buttonselectValue); panel.add(labelYears); panel.add(txtYears); panel.add(labelRate); panel.add(txtRate); panel.add(buttonCalc); panel.add(buttonClear); panel.add(buttonExit); setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Loan Plan")); // Creates etched border add(panel, BorderLayout.CENTER); add(scrollResult, BorderLayout.SOUTH); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable(false); setTitle("Mortgage Calculator"); setVisible(true); } public void buttonEnterValuesActionPerformed(ActionEvent e) { if (buttonEnterValue.isSelected()) { // Returns true if button is selected. 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); panel.add(buttonExit); setVisible(true); } } public void buttonselectValuesActionPerformed(ActionEvent e) { if (buttonselectValue.isSelected()) { // Returns true if button is selected. 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); panel.add(buttonExit); setVisible(true); } } // Calculate Information public void onButtonCalculate() { double loanAmt = Double.parseDouble(txtPrincipal.getText()); assignLoanAmount(loanAmt); // Assign Amount of Loan if (buttonEnterValue.isSelected()) { double rate = Double.parseDouble(txtRate.getText()); assignLoanRate(rate); double years = Double.parseDouble(txtYears.getText()); assignLoanTerm(years * 12); } 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); } } calcMonthlyPayment(); // Calculate Monthly Payment of Loan calcMonthlyInterest(); // Calculate Monthly Interest on Loan calcMonthlyPrinciple(); // Calculate Monthly Principle of Payment calcLoanBalance(); // Calculate Loan Balance calcNewBalance(); // Calculate New Balance Each Month displayAmounts(); // Display All Amounts monthlyLoanAmount(); monthlyInterestBalance(getAssignLoanAmount(), getAssignLoanTerm(), getAssignLoanRate()); } // Information for Button public void onButtonClear() { txtPrincipal.setText(""); txtYears.setText(""); txtRate.setText(""); result.setText(""); } // Information for Exit Button public void onButtonExit() { System.exit(0); } // 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 calcMonthlyPayment() { interestMonthly = (loanRate / 100) / 12; monthlyPayment = principalBalance * ((interestMonthly * (Math.pow((1 + interestMonthly), loanTerm))) / (Math.pow((1 + interestMonthly), loanTerm) - 1)); } public void calcMonthlyInterest() { monthlyInterestRate = (loanRate / 12) / 100; interestMonthly = principalBalance * monthlyInterestRate; } public void calcMonthlyPrinciple() { monthlyPrinciple = monthlyPayment - interestMonthly; } public void calcLoanBalance() { loanBalance = principalBalance - monthlyPrinciple; } public void calcNewBalance() { 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 monthlyInterestBalance(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 } } // End Wk4calcjp2 program
Wk4calcjp2 newloan = new Wk4calcjp2()); (error says ';' expected) what does that mean?
[Edit: fixed code tags]
Joanne Neal
Rancher
Posts: 3742
16
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It means it's expecting a ; after the closing bracket of the method call, but the first character it finds is actually a second closing bracket.
Joanne
LeeAnne Murphy
Greenhorn
Posts: 18
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ah got it...I removed the 2nd bracket.. and it cleared the error. Thank you.
Campbell Ritchie
Marshal
Posts: 79632
380
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It takes a long time to get used to the compiler error messages. Google for
mindprod java compiler error
and
you should
find some helpful information.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Help with Java Mortgage Program
Help with errors again
Java Rookie Help Requested
more help with java problem
last week of class last assignment. Any help is appreciated.
More...