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: Netbeans GUI help

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Netbeans GUI help

    I am hoping to get some help with a mortgage calculator assignment I am doing in Netbeans. Here is what I need to do: Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:
    - 7 years at 5.35%
    - 15 years at 5.5%
    - 30 years at 5.75%
    Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by 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.
    The issue I am having is that I am not getting the correct results. No matter what I put in I only get the interest rate and years in the results text box instead of monthly payment and interest. I cant figure out what im doing wrong.

    package CR5;
     
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
     
     
    public class ChangeRequest5 extends javax.swing.JFrame {
     
        public int[] years = new int[]{7, 15, 30};
        public double[] interestRates = new double[]{5.35, 5.5, 5.75};
        DecimalFormat decimalPlaces = new DecimalFormat("0.00");
     
     
        public ChangeRequest5() {
            initComponents();
        }
     
     private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            System.exit(0);//exits program
        }                                          
     
        private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            loanAmountField.setText(null);//clears loan amount
            resultsTextField.setText(null);//clears results field
            loanComboBox.setSelectedIndex(0);//resets combo box
        }                                           
     
        private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) { 
            //creates array for interest rate                                       
            double[] interestRate = new double[3];
            interestRate[0] = 5.35;
            interestRate[1] = 5.5;
            interestRate[2] = 5.75;
     
            //creates array for the number of years
            int[] numberOfYears = new int[3];
            numberOfYears[0] = 7;
            numberOfYears[1] = 15;
            numberOfYears[2] = 30;
            {
     
     
     
                int X = loanComboBox.getSelectedIndex();
                while (X < 3) {
     
                    //declare variables
                    double loanAmount = 200000; //Principle
                    double rate = 0.0;	 //monthly interest rate
                    double noOfMonths = 0.0;	// Number of months for the loan
                    double monthlyPayment = 0.0;	//Monthly Payment
     
                    //converts dollar amounts to a decimal format 
                    DecimalFormat cash = new DecimalFormat("$0.00");
     
                    //calculate monthly interest rate
                    rate = interestRate[X] / (12 * 100);
     
                    //calculate total number of months for loan
                    noOfMonths = numberOfYears[X] * 12;
     
                    //Calculate Monthly Payment
                    noOfMonths = (loanAmount * (rate * (Math.pow((1 + rate), monthlyPayment)) / (Math.pow((1 + rate), monthlyPayment) - 1)));
     
                    //begins the loop process for 360 payments
                    for (int i = 1; i <= noOfMonths; i++) {   //begins the loop process for 360 payments
     
                        //displays results
                        this.resultsTextField.setText(+interestRate[X] + "% for " + numberOfYears[X] + " years is " + cash.format(monthlyPayment));
                        X = X + 1;
                        resultsTextField.setText("Number of payments=" + numberOfYears + "Monthly Payment= " + cash.format(monthlyPayment) + "Interest Payment= " + cash.format(interestRates) + "Mortgage Balance= " + cash.format(loanAmount));
     
                    }  
        }       
     
    private void loanComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                             
     
        }                                            
     
        private void resultsTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
     
        }
     
     
     
        private javax.swing.JButton calculateButton;
        private javax.swing.JButton clearButton;
        private javax.swing.JButton exitButton;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JScrollBar jScrollBar1;
        private javax.swing.JTextField loanAmountField;
        private javax.swing.JComboBox loanComboBox;
        private javax.swing.JLabel loanLabel;
        private javax.swing.JTextField resultsTextField;
        // End of variables declaration
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Netbeans GUI help

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    not getting the correct results.
    Please post the programs input and output and add comments describing what is wrong with the output and show what the output should be.

    Add some println statements that print out the values of the variables as the program executes.

Similar Threads

  1. Help with NetBeans plz
    By moriarity in forum Object Oriented Programming
    Replies: 3
    Last Post: January 12th, 2012, 05:39 AM
  2. NetBeans help please!
    By JuLiAnc in forum AWT / Java Swing
    Replies: 4
    Last Post: January 9th, 2012, 06:16 AM
  3. Netbeans 6.8
    By selmaky in forum Java IDEs
    Replies: 1
    Last Post: May 14th, 2011, 03:08 PM
  4. New to NetBeans
    By _lithium_ in forum Java IDEs
    Replies: 0
    Last Post: March 1st, 2011, 08:48 PM
  5. Netbeans help
    By [Kyle] in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2009, 06:32 PM