Question

Please help me do this program.

Add some comments on it.

*15.5 (Create an investment-value calculator) Write a program that calculates the future value of an investment at a for theExerdise15 05 Investment Amunt 10000 Number of Years: Annual Interest Rate: 3.25 Future value: S11386.28 Calaulate (b)

*15.5 (Create an investment-value calculator) Write a program that calculates the future value of an investment at a for the calculation is given interest rate for a specified number of years. The formula investmentAmount * (1monthlyInterestRate ) years *12 futureValue Use text fields for the investment amount, number of years, and annual interest rate. Display the future amount in a text field when the user clicks the Calculate button, shown in Eigure 15.27h as
Exerdise15 05 Investment Amunt 10000 Number of Years: Annual Interest Rate: 3.25 Future value: S11386.28 Calaulate (b)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below, I have mentioned all the details in the comments:

InvestmentCalc.java
//import java files

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//class definition
public class InvestmentCalc extends JFrame{
    //Declare the required componenets
    private JLabel jlblInvestment,jlblYears,jlblRate,jlblFutureValue;
    private JTextField jtfInvestment,jtfYears,jtfRate,jtfFutureValue;
    private JButton jbtnCalculate;

    //size of the frame
    private static final int WIDTH = 500, HEIGHT = 250;

    //default constructor
    public InvestmentCalc(){
        //set the title of the frame
        setTitle("Exercise15_05");
        Container cntCalc = getContentPane();
        cntCalc.setLayout(new GridLayout(5,1));
        //create the label
        jlblInvestment = new JLabel("Investment Amount:",SwingConstants.RIGHT);
        jlblYears = new JLabel("Number of Years:",SwingConstants.RIGHT);
        jlblRate = new JLabel("Annual Interest Rate:",SwingConstants.RIGHT);
        jlblFutureValue = new JLabel("Future Value:",SwingConstants.RIGHT);


        //create the Text fields
        jtfInvestment = new JTextField();
        jtfYears = new JTextField();
        jtfRate = new JTextField();
        jtfFutureValue = new JTextField();


        //create The buttons
        jbtnCalculate = new JButton("Calculate");

        //add all components to the pane
        cntCalc.add(jlblInvestment);
        cntCalc.add(jtfInvestment);

        cntCalc.add(jlblYears);
        cntCalc.add(jtfYears);

        cntCalc.add(jlblRate);
        cntCalc.add(jtfRate);

        cntCalc.add(jlblFutureValue);
        cntCalc.add(jtfFutureValue);

        //dummy component
        cntCalc.add(new JLabel());
        cntCalc.add(jbtnCalculate);


        //Register action listener to the buttons
        jbtnCalculate.addActionListener(new CalculateListener());

        //set the dimensions and property of the window
        //set the frame's property

        setSize(WIDTH,HEIGHT);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }//end constructor
    //CalculateListener inner class

    private class CalculateListener implements ActionListener{
        //actionPerformed method
        public void actionPerformed(ActionEvent ae){
            //local variables
            double investmentAmount = Double.parseDouble(jtfInvestment.getText());
            int years = Integer.parseInt(jtfYears.getText());
            double monthlyInterestRate =
                    Double.parseDouble(jtfRate.getText()) / 1200;
            //set the value
            jtfFutureValue.setText(String.format("$%.2f",
                    (investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12))));
        }
    }

    //main method
    public static void main(String args[]){
        InvestmentCalc cal = new InvestmentCalc();
    }

}

Output:

X Exercise15_05 Investment Amount: 10000 Number of Years:4 Annual Interest Rate:3.25 Future Value: $11386.28 Calculate

Add a comment
Know the answer?
Add Answer to:
Please help me do this program. Add some comments on it. *15.5 (Create an investment-value calculator)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this code: Write a program that calculates the future value of an...

    I need help with this code: Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is as follows: futureValue = investmentAmount * (1 + monthlyInterestRate)years*12 Use text fields for interest rate, investment amount, and years. Display the future amount in a text field when the user clicks the Calculate button, as shown in the following figure. It needs to be done in...

  • ***Please use java code for the question below*** Write a program that calculates the future value...

    ***Please use java code for the question below*** Write a program that calculates the future value of a given investment at a given interest rate for a specified number of years. The formula for this calculation is: value = investmentAmount * (1 + monthly interest rate)years*12 Use text fields for the user to enter the numbers (Investment Amount, Number of Years, and Annual Interest). To get/load data from the textbox, (in this case doubles) use the following structure: (bold are...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

  • Write a program that calculates the amount of money that you must invest In a savings...

    Write a program that calculates the amount of money that you must invest In a savings account at a given interest rate for a given number of years to have a certain dollar amount at me end of the period Y our program will ask the user for the amount the user wants to have at the end of the term (future value). the number of years the user plans to let the money stay in the account, and the...

  • Write a program that prints the accumulated value of an initial investment invested at a specified...

    Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:...

  • CIT 149 JAVA 1 programming question? There will be two files for this problem. The first...

    CIT 149 JAVA 1 programming question? There will be two files for this problem. The first one, called FutureValue will hold the main method. The second file called FinancialUtils will hold the two methods that will display what the program will do, and perform the calculations. In the main method, which controls the logic of the program, you will first call the displayInstructions method which will display a statement of what the program will do. You will write this description...

  • MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay-...

    MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay- ments based on compound interest formulas The program should prompt a user to input the amount borrowed (principal), p, the number of monthly payments, n, and an annual interest rate in R percent. The program should convert the annual interest rate R into a monthly interest rate...

  • I need this done in java plz, add comments for every single method. also, make as simple as po...

    i need this done in java plz, add comments for every single method. also, make as simple as possible. 3. Write a GUI for computing the statistics of numbers input from the user. The GUI should have a text field and a button for adding floating point numbers. Each time a number is entered have a label show the current max, min and average. Have your GUI accept numbers whether the button is pressed or the enter key is pressed...

  • Computing Future Investment Value Problem Description: Write a method that computes future investment value at a...

    Computing Future Investment Value Problem Description: Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the following formula: 12 futurelnvestmentValue investmentAmountx(1+ monthlylnterestRate) Use the following method header: publie static double futureInvestnentValue double investnentAmount, double monthlyInterestRate, int years) For example, futur Investmentvalue( 1eeee, อ.es/12, 5) returns 12833.59 Write a test program that prompts the user to enter the investment amount (e.g. 1000) and the interest...

  • Program Specification: This project involves implementing a Java program that performs a calculation of payments associated...

    Program Specification: This project involves implementing a Java program that performs a calculation of payments associated with loans. The program shall allow a user to enter the following data: annual interest rate the loan (i.e. , number of years), and the loan amount. A GUI like the one below must be used. Loan Calculator Annual Interest Rate: Number of Years Loan Amount: Monthly Payment Total Payment Calculate When the user presses the calculate button, the monthly payment and total amount...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT