Results 1 to 5 of 5

Thread: Homework help

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default Homework help

    I need this program to display mortgage table. I really appreciate any help
    Java Code:
    import java.text.NumberFormat;
    
    /*Robin Williams
     * PRG/421
     * Week 3, Change Request 5
     * GUI for Mortgage Calculator with Array/Menu
     */
    
     
    public class MortgageCalculatorJFrame extends javax.swing.JFrame {
    
        /** Creates new form MortgageCalculatorJFrame */
        public MortgageCalculatorJFrame() {
            initComponents();
        }
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            loanAmountLbl = new javax.swing.JLabel();
            loanChoiceLbl = new javax.swing.JLabel();
            loanAmountTxt = new javax.swing.JTextField();
            loanChoiceCmb = new javax.swing.JComboBox();
            calculateButton = new javax.swing.JButton();
            clearButton = new javax.swing.JButton();
            quitButton = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            resultsTxtArea = new javax.swing.JTextArea();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            loanAmountLbl.setText("Loan Amount");
    
            loanChoiceLbl.setText("Loan Choice");
    
            loanChoiceCmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%" }));
            loanChoiceCmb.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loanChoiceCmbActionPerformed(evt);
                }
            });
    
            calculateButton.setText("Calculate");
            calculateButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    calculateButtonActionPerformed(evt);
                }
            });
    
            clearButton.setText("Clear");
            clearButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    clearButtonActionPerformed(evt);
                }
            });
    
            quitButton.setText("Quit");
            quitButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    quitButtonActionPerformed(evt);
                }
            });
    
            resultsTxtArea.setColumns(20);
            resultsTxtArea.setRows(5);
            jScrollPane1.setViewportView(resultsTxtArea);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(72, 72, 72)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(loanAmountLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(loanChoiceLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(86, 86, 86)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(loanAmountTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                                .addComponent(loanChoiceCmb, javax.swing.GroupLayout.Alignment.TRAILING, 0, 230, Short.MAX_VALUE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(100, 100, 100)
                            .addComponent(quitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(54, 54, 54))
                .addGroup(layout.createSequentialGroup()
                    .addGap(28, 28, 28)
                    .addComponent(calculateButton)
                    .addContainerGap(377, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                    .addGap(55, 55, 55)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(50, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(47, 47, 47)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(loanAmountLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(loanAmountTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(59, 59, 59)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(loanChoiceLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(loanChoiceCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(29, 29, 29)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(calculateButton)
                        .addComponent(quitButton)
                        .addComponent(clearButton))
                    .addGap(34, 34, 34)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(23, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void loanChoiceCmbActionPerformed(java.awt.event.ActionEvent evt) {                                              
            
        }                                             
    
        @SuppressWarnings("empty-statement")
        private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
    
            double dblPrincipal = (Double.parseDouble (loanAmountTxt.getText()));                  //principal amount
            double [] dblInterestRate = {5.35,5.5,5.75};     //intialized the array with values(interest rate)
            int []intLoanTermYear  = {7,15,30};              //intialized the array with values(loan term)
            double [] dblMonthlyPayment = {0,0,0};            //intialized the array with zero values(monthly payment)
            double [] dblMonthlyInterestRate= {0,0,0};        //intialized the array with zero values(monthly interest rate)
            int [] intLoanTermMonth = {0,0,0};               //intialized the array with zero values(loan term in months)
            int box = loanChoiceCmb.getSelectedIndex();
            double dblcurrentbalance = 0;
            double dblcurrentmonthlyPrincipalpayment = 0;
            double dblcurrentmonthlyInterestpaid = 0;
            double dblcurrentmonthlyprincipal = 0;
            double dblpreviousmonthlybalance = 0;
            if (dblPrincipal > 0)
            { dblPrincipal = (Double.parseDouble (loanAmountTxt.getText()));
                dblMonthlyInterestRate[box] = dblInterestRate[box]/(12 * 100); //calculate monthly interest rate per array
    
    
                intLoanTermMonth[box] = intLoanTermYear[box] * 12;             //calculate number of months of loan
    
                /* Monthlypayment formula using array index values */
                dblMonthlyPayment[box] = dblPrincipal * ( dblMonthlyInterestRate[box] / (1 - (Math.pow((1 + dblMonthlyInterestRate[box]),-(intLoanTermMonth[box])))));
    
                /* Calculation formulas*/
                    dblcurrentmonthlyInterestpaid = (dblPrincipal * dblMonthlyInterestRate[box]);          //current monthly interest
                    dblcurrentmonthlyPrincipalpayment = (dblMonthlyPayment[box] - dblMonthlyInterestRate[box]); //current monthlt principal payment
                    dblcurrentmonthlyprincipal = (dblPrincipal - dblcurrentbalance);                               //calculate the new balance
                    dblpreviousmonthlybalance =  dblcurrentmonthlyprincipal;
    //Print out Monthly Payment Amount
                NumberFormat CurrencyFormat = NumberFormat.getCurrencyInstance();
    resultsTxtArea.append("The Loan Principal is " +(CurrencyFormat.format (dblPrincipal))+ "." + "\n"+"The loan's interest rate is" +""+"" + dblInterestRate[box] +"%." + "\n"+"The loan term is"+""+intLoanTermYear[box]+""+ "years."+"\n"+"The monthly payment will be"+""+(CurrencyFormat.format (dblMonthlyPayment[box])));
    
    
                    int intlinecounter=1;
    
                    for(intlinecounter=1; intlinecounter<=intLoanTermMonth[box]; intlinecounter++)
                    {
                   // Formulas to perform calculations
                      dblMonthlyInterestRate[box] = dblpreviousmonthlybalance * dblMonthlyInterestRate[box];
                      dblcurrentbalance = dblMonthlyPayment[box] - dblcurrentmonthlyInterestpaid;
                      dblcurrentmonthlyprincipal = dblpreviousmonthlybalance - dblcurrentbalance;
                      dblpreviousmonthlybalance = dblcurrentmonthlyprincipal;
    
    
               if(intlinecounter % 20 == 0)
    {              intlinecounter=1;
                   System.out.println("Press any key to continue");
                                    try
                                    {  System.in.read();
                                    }catch (Exception e){;
                                            }
                
                
                
            }
                    }}
        }                                               
        private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
           System.exit(0);
        }                                          
    
        private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            loanAmountTxt.setText(null);
            loanChoiceCmb.setSelectedIndex(-1);
            resultsTxtArea.setText(null);
        }                                           
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MortgageCalculatorJFrame().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton calculateButton;
        private javax.swing.JButton clearButton;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JLabel loanAmountLbl;
        private javax.swing.JTextField loanAmountTxt;
        private javax.swing.JComboBox loanChoiceCmb;
        private javax.swing.JLabel loanChoiceLbl;
        private javax.swing.JButton quitButton;
        private javax.swing.JTextArea resultsTxtArea;
        // End of variables declaration                   
    
    }

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    10

    Default

    Quote Originally Posted by lackingunderstanding4now View Post
    I need this program to display mortgage table. I really appreciate any help
    Pues, ¿Cuál es tu problema?

    What's not working? Details are important.

  3. #3
    MadJack is offline Member
    Join Date
    Sep 2010
    Location
    Qc
    Posts
    31
    Rep Power
    0

    Default

    Quote Originally Posted by curmudgeon View Post
    Pues, ¿Cuál es tu problema?

    What's not working? Details are important.
    I was about to say the same thing.

    Pretty hard to help when you don't know what's wrong. :/

  4. #4
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Nothing displays, but in the netbeans ide. "Press any key to continue" shows up

  5. #5
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    10

    Default

    Quote Originally Posted by lackingunderstanding4now View Post
    Nothing displays, but in the netbeans ide. "Press any key to continue" shows up
    That's cuz you're telling it to so here:
    Java Code:
                if (intlinecounter % 20 == 0) {
                   intlinecounter = 1;
                   System.out.println("Press any key to continue");
                   try {
                      System.in.read();
                   } catch (Exception e) {
                      ;
                   }
    
                }
    By the way, is this your code or have you borrowed it from a source on the net? If the latter, where did you get it from?

Similar Threads

  1. Homework help please
    By chick in forum New To Java
    Replies: 22
    Last Post: 03-19-2010, 07:39 AM
  2. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM
  3. help with homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 7
    Last Post: 04-07-2009, 01:34 AM
  4. Homework help...
    By robrobrob in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 04:24 AM
  5. Need help with homework.
    By JavaNewbie0000 in forum New To Java
    Replies: 2
    Last Post: 07-31-2008, 03:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •