JustAnswer > Programming
Ask A Question|Register|Login|Help
JustAnswer

Programming

Ask a Programming Question, Get an Answer ASAP!

Have your own Programming question?

3 Programmers are Online Now
characters left:
Not a Programming Question?
Bookmark and Share

Question

I need to modify my Java program with the below requirements:

Use an array for the mortgage data for the different loans. Read the interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart. Allow the user to loop back and enter a new amount and make a new selection or quit.

My program is as follows:

import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import java.lang.*;
//GUI screen
public class Mortgage extends JApplet {
     private String[] terms={"7","15","30"};
     private double[] rates={0.0535,0.055,0.0575};
     private JLabel amountLabel=new JLabel("Loan amount: ");
     private JTextField amount=new JTextField();
     private JLabel termLabel=new JLabel("Term (Type Or pick from list): ");
     private JTextField term=new JTextField();
     private JLabel rateLabel=new JLabel("Interest rate (in decimal): ");
     private JTextField rate=new JTextField();
     private JComboBox termList = new JComboBox(terms);
     private JLabel payLabel=new JLabel("Monthly Payment: ");
     private JLabel payment=new JLabel();
     private JButton calculate=new JButton("Calculate");
     private JButton clear=new JButton("Clear");
     private JButton exit=new JButton("Exit");
     private JTextArea paymentSchedule=new JTextArea();
     private JScrollPane schedulePane=new JScrollPane(paymentSchedule);
     private Container cp = getContentPane();
     
     public void init() {
          // Take care of termList (Default terms)     
          termList.setSelectedIndex(0);
          termList.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    JComboBox cb = (JComboBox)e.getSource();
                    // the source of the event is the combo box
                  String termYear = (String)cb.getSelectedItem();
                  term.setText(termYear);
                  int index=0;
                  switch (Integer.parseInt(termYear)) {
                       case 7: index=0; break;
                       case 15: index=1; break;
                       case 30: index=2; break;
                  }
                  rate.setText(rates[index]+"");
               }
          });
          
          // Assigning three buttons
          calculate.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    try {// exception handler
                         // calculate monthly payment
                         double p=Double.parseDouble(amount.getText());
                         double r=Double.parseDouble(rate.getText())/12;
                         double n=Integer.parseInt(term.getText())*12;
                         double monthlyPayment=p*Math.pow(1+r,n)*r/(Math.pow(1+r,n)-1);
                         DecimalFormat df = new DecimalFormat("$###,###.00");
                         payment.setText(df.format(monthlyPayment));
                         // calculate the loan
                         double principal=p;
                         int month;
                         StringBuffer buffer=new StringBuffer();
                         buffer.append("Month\tAmount\tInterest\tBalance\n");
                         for (int i=0; i<n; i++) {
                              month=i+1;
                              double interest=principal*r;
                              double balance=principal+interest-monthlyPayment;
                              buffer.append(month+"\t");
                              buffer.append(new String(df.format(principal))+"\t");
                              buffer.append(new String(df.format(interest))+"\t");
                              buffer.append(new String(df.format(balance))+"\n");
                              principal=balance;
                         }
                         paymentSchedule.setText(buffer.toString());
                    } catch(NumberFormatException ex) { //Catch the exception error and show the error.
                         System.out.println("Please type the correct numerical number!Please avoid using other characters");
                    }
               }
          });
          clear.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    amount.setText("");
                    payment.setText("");
                    paymentSchedule.setText("");
               }
          });
          exit.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    System.exit(1);
               }
          });
          
          JPanel upScreen=new JPanel();
          upScreen.setLayout(new GridLayout(5,2));
          upScreen.add(amountLabel); upScreen.add(amount);     
          upScreen.add(termLabel); upScreen.add(term);
          upScreen.add(new Label()); upScreen.add(termList);
          upScreen.add(rateLabel); upScreen.add(rate);
          upScreen.add(payLabel); upScreen.add(payment);
          JPanel buttons=new JPanel();
          buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
          buttons.add(calculate); buttons.add(clear); buttons.add(exit);
          JPanel up=new JPanel();
          up.setLayout(new BoxLayout(up, BoxLayout.Y_AXIS));
          up.add(upScreen); up.add(buttons);
          cp.add(BorderLayout.NORTH, up);
          cp.add(BorderLayout.CENTER, schedulePane);
     }
     public static void main(String[] args) {
          JApplet applet = new Mortgage();
          JFrame frame = new JFrame("Mortgage Calculator");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setResizable(false);
          frame.getContentPane().add(applet);
          frame.setSize(380,400);
          applet.init();
          applet.start();
          frame.setVisible(true);
     }
}

Submitted: 97 days and 18 hours ago.
Category: Programming
Value: $22
Status: AWAITING CUSTOMER ACTION
+
Read More

Optional Information

Computer OS: Windows XP
Browser: IE

Already Tried:
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import java.lang.*;
//GUI screen
public class Mortgage extends JApplet {
     private String[] terms={"7","15","30"};
     private double[] rates={0.0535,0.055,0.0575};
     private JLabel amountLabel=new JLabel("Loan amount: ");
     private JTextField amount=new JTextField();
     private JLabel termLabel=new JLabel("Term (Type Or pick from list): ");
     private JTextField term=new JTextField();
     private JLabel rateLabel=new JLabel("Interest rate (in decimal): ");
     private JTextField rate=new JTextField();
     private JComboBox termList = new JComboBox(terms);
     private JLabel payLabel=new JLabel("Monthly Payment: ");
     private JLabel payment=new JLabel();
     private JButton calculate=new JButton("Calculate");
     private JButton clear=new JButton("Clear");
     private JButton exit=new JButton("Exit");
     private JTextArea paymentSchedule=new JTextArea();
     private JScrollPane schedulePane=new JScrollPane(paymentSchedule);
     private Container cp = getContentPane();
     
     public void init() {
          // Take care of termList (Default terms)     
          termList.setSelectedIndex(0);
          termList.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    JComboBox cb = (JComboBox)e.getSource();
                    // the source of the event is the combo box
                  String termYear = (String)cb.getSelectedItem();
                  term.setText(termYear);
                  int index=0;
                  switch (Integer.parseInt(termYear)) {
                       case 7: index=0; break;
                       case 15: index=1; break;
                       case 30: index=2; break;
                  }
                  rate.setText(rates[index]+"");
               }
          });
          
          // Assigning three buttons
          calculate.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    try {// exception handler
                         // calculate monthly payment
                         double p=Double.parseD

Posted by Cherryl Lewis 97 days and 2 hours ago.

Answer

What development environment are you using for this project? JCreator LE, for instance? Could you post all your program files and the assignment using www.rapidshare.com? It is a free service and once your files are uploaded you would post the link they give you, here.

I just finished a java application for someone here, and I can help you with this today.

96 days and 20 hours ago.

Reply

I am using JCreatorPro with Java runtime 1.6. You can download the file from http://rapidshare.com/files/268556459/Mortgage.java.html

Posted by Cherryl Lewis 96 days and 17 hours ago.

Answer

I have downloaded the file and was able to open and run it in JCreator LE. It is 10 pm in my time zone now (CST), so I will work on this first thing in the morning. Let me understand exactly what you need done. Please correct where I have it incorrectly stated, please.

1. Read a list of interest rates from a sequential file. Is that one interest rate per row, or comma delimited? Should I provide the same interest rates you have in your program array, or add other test data?

2. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. It looks like your program already does this correctly--I can check the mathematical formulas for you. So nothing more needs to be done.

3. Add graphics in the form of a chart. Do you have a suggested way of showing the chart or positioning it? For instance, does this mean a graph of the amount of interest paid each payment or does it mean to put the data into a table form rather than the list you currently have it in? If you can upload a scan of the assignment, that could help a lot.

4. Allow the user to loop back and enter a new amount and make a new selection or quit. No questions on this--you want the program to be usable repetitively. Would a clear button be appropriate?

I'll post the application by 10 am Tuesday morning (CST).



96 days and 17 hours ago.

Reply

Sorry, I did not know if you were going to respond in time, thus I purchased another solution. Thanks for your help. I will save your name as an expert for later solutions.

Thanks again.

Answer

No problem--I understand. Thanks for letting me know.

Picture
Expert: Cherryl Lewis
Pos. Feedback: 100.0 %
Accepts: 
Answered: 8/18/2009

Computer Software Engineer

MCSD * C# VB C++ .NET * Excel * MS Access * SQL Server * Oracle * Java * Python * Pascal

+
Read More

Related Programming Questions

  • Write a class, HashTable.java, to implement a hash table wit...
  • Write an application that accepts a user's password from the
  • Locked: I am taking a class in Java and need to know how to ...
  • For Scott only NO other answers! Generate an object-oriented
  • Write a program that asks the user to enter today's sales fo...
  • WE paid 19.95 to download Scrabble on Friday. To no avail.
  • I need to find out what numbers in column A match numbers in
  • I need to generate an object-oriented design for a system th...



Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.
Question List | Become an Expert | Terms of Service | Security & Privacy | About Us
© 2003-2009 JustAnswer Corp.