Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Not Displaying what I need

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Not Displaying what I need

    * This program will calculate and display the monthly
    * payment amount to fully amortize an input loan amount
    * over a specific term at percentage of interest from a list
    * selection menu of of available mortgage loans.
    I've tried taken my code from the previous assignment and input that here. This is homework, just seeking help and understanding. PLEASE!!!
    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;
     
            {
     
                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;
     
     
                    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;
     
    //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])));
     
               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
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Not Displaying what I need

    More information is needed. Any compile time or runtime errors? Are you receiving an output different than you would expect? If so, describe in all its detail.

Similar Threads

  1. Applet Help: Parsing and displaying labels
    By katyprim in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 11th, 2010, 09:32 AM
  2. Displaying things in gui
    By KrisTheSavage in forum AWT / Java Swing
    Replies: 2
    Last Post: March 29th, 2010, 12:21 PM
  3. Need help with String Trimming.. and displaying Keys on maps.
    By bh-chobo in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 9th, 2009, 01:15 PM
  4. [SOLVED] displaying sum of harmonic series
    By sriraj.kundan in forum Algorithms & Recursion
    Replies: 2
    Last Post: June 15th, 2009, 11:42 PM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM