I just cannot figure out what is wrong, so tried. Can someone please help me so I can finish this today or tomorrow please.

//adds all 10 panels together
        this.add(mainpanel);

        //set see the frame
        setVisible(true);
    }
 JOptionPane.showMessageDialog(null,"Oringinal Balance = $" + recieveAmount +
                           "\nPayment#" + x + "\nMonthly Payment$" + fixdecimal.format(payment)+
                           "\nRemaining Balance $" + fixdecimal.format(remainBalance) + "\nInterest Paid $" +
                           fixdecimal.format(interestout), "Payment History", JOptionPane.PLAIN_MESSAGE);
                      }

=say method format(double) no symbol, setVisible no symbol and the add. Please

Recommended Answers

All 12 Replies

You haven't posted enough code for anyone to help with this. What context are those calls being made in? What is "fixdecimal"?

import javax.swing.*;
import java.awt.Event.*;
import java.lang.Math.*;
import java.text.NumberFormat;
import javax.swing.ButtonGroup;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.lang.String;
import java.util.*;
import java.lang.Object;
/**
 *
 * 
 */


    /**
     * @param args the command line arguments
     */

     class MortgageCalculator7 extends JFrame implements ActionListener {

    public void actionPerformed(ActionEvent e) {
        actionPerformed(e);throw new UnsupportedOperationException("Not supported yet.");
    }
     }
public class Main {
    {
}

    public static void main (String[] args){
        JFrame window = new MortgageCalculator7();
        window.setTitle("Mortgage Calculator7");
        window.setLocation(new Point(0, 0));
        window.setSize(new Dimension(500, 700));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    {

    }
       new MortgageCalculator7();
    }

    private static void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


    //Decaring buttons, text fields, and labels
    private JButton calculate;
    private  JButton exit;
    private JButton calc;
    private JTextField enterAmount;
    private JTextField enterInterest;
    private JTextField enterMonth;
    private JLabel loan;
    private JLabel interest;
    private JLabel mRate;
    private JLabel blankspace;
    private JLabel data;
    private JLabel data1;
    private JLabel data2;
    private JRadioButton term7;
    private JRadioButton term15;
    private JRadioButton term30;
    private Object paymentFormat;
    private boolean drawn;
    private double receiveAmount;
    private int receiveTerms;
    private Object fixdecimal;
    private Object frame;
    private boolean setVisible;
    private int format;

    public void MortgageCalculator7()
    {
    }
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();

    {


        //Creat layout
        JPanel mainpanel = new JPanel();

        //panel1
        JPanel panel1 = new JPanel();
        data = new JLabel("Please fill out amount of Loan");
        panel1.add(data);
        mainpanel.add(panel1);

        JPanel panel2 = new JPanel();
        loan = new JLabel("Amount of Loan");
        enterAmount = new JTextField(8);
        panel2.add(loan);
        panel2.add(enterAmount);
        mainpanel.add(panel2);

        JPanel panel3 = new JPanel();
        data1 = new JLabel("Choose between rate & term");
        panel3.add(data1);
        mainpanel.add(panel3);

        JPanel panel4 = new JPanel();
        ButtonGroup choice = new ButtonGroup();
        term7 = new JRadioButton("30 Years @ 5.75%");
        term15 = new JRadioButton("15 Years @ 5.5%");
        term30 = new JRadioButton("7 Years @ 5.35%");
        panel4.add(term7);
        choice.add(term7);
        panel4.add(term15);
        choice.add(term15);
        panel4.add(term30);
        choice.add(term30);
        mainpanel.add(panel4);

        JPanel panel5 = new JPanel();
        calc = new JButton("Calculate Choice");
        panel5.add(calc);
        mainpanel.add(panel5);

        JPanel panel6 = new JPanel();
        data2 = new JLabel("Or fill in yourself");
        panel6.add(data2);
        mainpanel.add(panel2);

        JPanel panel7 = new JPanel();
        interest = new JLabel("Interest Rate");
        enterInterest = new JTextField(8);
        panel7.add(interest);
        panel7.add(enterInterest);
        mainpanel.add(panel7);

        JPanel panel8 = new JPanel();
        mRate = new JLabel("Term of Loan");
        enterMonth = new JTextField(8);
        panel8.add(mRate);
        panel8.add(enterMonth);
        mainpanel.add(panel8);

        JPanel panel9 = new JPanel();
        blankspace = new JLabel("");
        panel9.add(blankspace);
        mainpanel.add(panel9);

        JPanel panel10 = new JPanel();
        calculate = new JButton("Calculate");
        exit = new JButton("Exit");
        panel10.add(calculate);
        panel10.add(exit);
        mainpanel.add(panel10);

        //Create Event Listener
        ClickListener click = new ClickListener();


        //Creat Action Listerers
        calculate.addActionListener((ActionListener) click);
        exit.addActionListener((ActionListener) click);
        calc.addActionListener((ActionListener) click);

        //adds all 10 panels together
        this.add(mainpanel);

        //set see the frame
        setVisible(true);
    }

  

    public Main() {
    }
  
    public void paint(Graphics g, int dblLoanDuration, int dblLoanAmount)
    {

       double width = 900;
       int height = 400;
       double x = 1;
       double y = 0;
       int counter = 0;
       double xincrement = (width/(dblLoanDuration*12));
       double yincrement = height/dblLoanAmount;

       g.drawString("Payments", 65, 10);
       while(counter<=10) {
           x = x+ xincrement;
           g.drawString(Integer.toString((int)((((dblLoanDuration*12)/10)*counter))), (int)((width/10)*counter)
                   +55, 20);
           counter++;
           drawn = true;
       }

       double amount = dblLoanAmount;
       double payment = amount/12;
       g.drawString("Amount", 0, 20);
       while (y <height)
       {
        y = y + (height/12);
        g.drawString(paymentFormat.format(amount), 0,(int)y);
        amount = amount-payment;
       }

       //Begin Events
       //Create ActionListener calculate.addActionListener(click);
       }


             public void actionPerformed(ActionEvent getevent) {
                 Object source = getevent.getSource();
               if ( getevent.getSource() == calc)//if user clicks the calculate button
               {
    {
    }



                try {

                     double recieveAmount = Double.parseDouble(enterAmount.getText());

                       //create the arrays for the three different loans
                       int Terms[] ={7, 15, 30};//loan in years

                       double InterestArray[] = {5.35, 5.5, 5.75};//interest as a percent

                       //Array 1
                       if (term7.isSelected()) {
                           double receiveInterest = InterestArray[0];
                           double receiveTerms = Terms[0];
                           double interest1 = (receiveInterest/(12*100));
                           double term1 = (receiveTerms*12);
                           double term2 = (1+interest1);
                           double pay1 = Math.pow(term2, +term1);
                           double payment = ((receiveAmount * interest1)/(1 - pay1));
                           double interestpay;
                           double remainBalance = recieveAmount;

                           //Create the number format
                           NumberFormat fixdecimal = NumberFormat.getNumberInstance();
                           fixdecimal.setMinimumFractionDigits(2);
                           fixdecimal.setMaximumFractionDigits(2);

                           //Create counter
                           for (int x = 1; x<= term1; x++)
                           {
                               interestpay = (remainBalance * interest1);
                               double interestout = 0;
                               remainBalance = (remainBalance -(payment - interestpay));
                               interestout = (interestout + interestpay);

                               //The output based on amount input and loan selection
                               JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
                                       "\nPayment#" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
                                       "\nInterest Paid $" + fixdecimal.format(interestpay),"Payment History", JOptionPane.PLAIN_MESSAGE);
                           }
                           //Exit or enter option
                           int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to input a new amount?" +
                                   "\n\n(chose Yes to continue or No to Exit)", "Continue" , JOptionPane.YES_NO_OPTION);
                           if (finalanswer == JOptionPane.NO_OPTION) {
                               //if user chooses 'yes' the answer field will blank out
                               enterAmount.setText(null);
                           }
                           //Array 2
                       }
                       else if (term15.isSelected()) {
                           double receiveInterest = InterestArray[1];
                           double receiveTerms = Terms[1];
                           double interest1 = (receiveInterest/(12*100));
                           double term1 = (receiveTerms*12);
                           double term2 = (1 + interest1);
                           double pay1 = Math.pow(term2,- term1);
                           double payment = ((receiveAmount * interest1)/(1 - pay1));
                           double interestpay;
                           double remainBalance = recieveAmount;

                           //Create number format
                           NumberFormat fixdecimal = NumberFormat.getNumberInstance();
                           fixdecimal.setMinimumFractionDigits(2);
                           fixdecimal.setMaximumFractionDigits(2);

                           //Create counter
                           for(int x =1; x<=term1; x++) {
                               interestpay = (remainBalance * interest1);
                               double interestout = 0;
                               remainBalance = (remainBalance - (payment - interestpay));
                               interestout = (interestout + interestpay);

                               JOptionPane.showMessageDialog(null,"Original Balance = $" + receiveAmount +
                                       "\nPayment#" + x +"\nMonthly Payment $" + fixdecimal.format(payment) +
                                       "\nRemaining Balance $" + fixdecimal.format(remainBalance) +
                                       "\nInterest Paid $" + fixdecimal.format(interestpay), "payment History", JOptionPane.PLAIN_MESSAGE);
                           }
                           //Exit or enter option
                           int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
                                   "\n\n(chose Yes to continue or No to Exit","Continue", JOptionPane.YES_NO_OPTION);
                           if(finalanswer == JOptionPane.NO_OPTION) {
                               System.exit(0);
                               //If user chooses 'yes' the amount field will blank out
                           }else if (finalanswer == JOptionPane.YES_OPTION){
                               enterAmount.setText(null);
                           }
                           //Array 3
                       }else if (term30.isSelected()){
                           double receiveInterest = InterestArray[2];
                           double recieveTerms = Terms[2];
                           double interest1 = (receiveInterest/(12*100));
                           double term1 = (recieveTerms * 12);
                           double term2 = (1 + interest1);
                           double pay1 = Math.pow(term2, - term1);
                           double payment = ((receiveAmount * interest1)/(1 - pay1));
                           double interestpay;
                           double remainBalance = receiveAmount;

                           //Creat number format
                           NumberFormat fixdecimal = NumberFormat.getNumberInstance();
                           fixdecimal.setMinimumFractionDigits(2);
                           fixdecimal.setMaximumFractionDigits(2);

                           //Create counter
                           for (int x =1; x <= term1; x++) {
                               interestpay = (remainBalance * interest1);
                               double interestout = 0;
                               remainBalance = (remainBalance - (payment - interestpay));
                               interestout = (interestout + interestpay);

                               JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
                                       "\nPayment#" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
                                       "\nRemaining Balance$" + fixdecimal.format(remainBalance) + "\nInterest Paid $" +
                                       fixdecimal.format(interestout), "Payment History", JOptionPane.PLAIN_MESSAGE); }

                           //Exit or enter option
                           int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
                                   "\n\n(chose Yes to continue or No to Exit", "Continue", JOptionPane.YES_NO_OPTION);
                           if(finalanswer == JOptionPane.NO_OPTION) {
                               System.exit(0);
                               //If the user chooses 'yes' the amount field will blank out
                           }else if (finalanswer == JOptionPane.YES_OPTION) {
                               enterAmount.setText(null);

                           }

                       }

                   }
                   catch (NumberFormatException e)  {

                   }
                   }
       //Create a new event

       if (getevent.getSource() == calculate){
           try {
                //Turn text entries into numbers
               double recieveAmount = Double.parseDouble(enterAmount.getText());
               double receivePerc = Double.parseDouble(enterInterest.getText());
               double receiveTerm = Double.parseDouble(enterMonth.getText());
               double receiveInterest = receivePerc;
               double interest1= (receiveInterest/(12 * 100));
               double term1 = (receiveTerms * 12);
               double term2 = (1 + interest1);
               double pay1 = Math.pow(term2, - term1);
               double payment = ((receiveAmount * interest1)/(1 - pay1));
               double interestpay;
               double remainBalance = receiveAmount;

               //Create number format
               for (int x =1; x <= term1; x++) {
                   interestpay = (remainBalance * interest1);
                   double interestout = 0;
                   remainBalance = (remainBalance - (payment - interestpay));
                   interestout = (interestout + interestpay);

                   JOptionPane.showMessageDialog(null,"Oringinal Balance = $" + recieveAmount +
                           "\nPayment#" + x + "\nMonthly Payment$" + fixdecimal.format(payment)+
                           "\nRemaining Balance $" + fixdecimal.format(remainBalance) + "\nInterest Paid $" +
                           fixdecimal.format(interestout), "Payment History", JOptionPane.PLAIN_MESSAGE);
                      }

               //Exit or enter option
               int finalanswer = JOptionPane.showConfirmDialog(null, "Would you like to enter a new amount?" +
                       "\n\n(chose Yes to continue or No to Exit)", "Continue", JOptionPane.YES_NO_OPTION);
               if (finalanswer == JOptionPane.NO_OPTION) {
                   System.exit(0);
                   //if the user chooses 'yes' the amount field will blank out
               }else if (finalanswer == JOptionPane.YES_OPTION) {
                  //resets the entry fields
                   enterAmount.setText(null);
                   enterInterest.setText(null);
                   enterMonth.setText(null);
               }

           }
           catch (NumberFormatException e) {
           }
  }
       if  ( getevent.getSource() == exit)
       {
       }
             }
       }

Well, your errors are mostly stemming from the fact that you've mangled in together a couple of different classes and have braces/blocks scattered all over the place.

Fix your class structure and you'll have a place to start. Half of that code isn't even in a method at all.

I will look at them again, and try to fixed them. Thanks for the point in the right direction. I am glad this is my last assignment, I stink in Java

Well, your errors are mostly stemming from the fact that you've mangled in together a couple of different classes and have braces/blocks scattered all over the place.

Fix your class structure and you'll have a place to start. Half of that code isn't even in a method at all.

I have tryed that and still have errors, still working on it.

I have tryed that and still have errors, still working on it.

I only have the one errr now.
g.drawString(paymentFormat.format(amount), 0,(int)y);
amount = amount-payment;
symbol : method format(double)
location: class java.lang.Object
g.drawString(paymentFormat.format(amount), 0,(int)y);

can some help me with this one error Please

You have paymentFormat declared as Object, but I'm assuming it should be a DecimalFormat?

You have paymentFormat declared as Object, but I'm assuming it should be a DecimalFormat?

Thank you I will change that.

Thank you I will change that.

Thanks that took care of that, I guess I am just dumb to this Java stuff, thank God it is my last one. Now all I get is a little blank screen, what have I now missed. I am sorry for being dumb to Java.

Thanks that took care of that, I guess I am just dumb to this Java stuff, thank God it is my last one. Now all I get is a little blank screen, what have I now missed. I am sorry for being dumb to Java.

Can someone look at this and tell me do I need to add data.addActionListener(this) to show all my panels

Adding an action listener to something just means that when some action occurs on it (such as clicking a button), the actionPerformed method will be called. So whatever code is in the actionperformed method will be executed if you, for example, add an action listener to a JButton then click on that JButton.

now I am really lost, how do I bring the info into the box. I am reviewing my last one, rying to see what I did different. I had button and label amorize table. Maybe I have been working on this to long.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.