Question

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 java fx.

Thank you in advance!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class FutureValue extends Application {

        TextField investment, rate, years, futureValue;

        @Override
        public void start(Stage myStage) {

                myStage.setTitle("Future Value");

                GridPane rootNode = new GridPane();
                rootNode.setPadding(new Insets(25));
                rootNode.setHgap(10);
                rootNode.setVgap(10);
                rootNode.setAlignment(Pos.CENTER);

                Scene myScene = new Scene(rootNode, 500, 500);
                
                rootNode.add(new Label("Investment Amount"), 0, 0);
                investment = new TextField();
                rootNode.add(investment, 1, 0);
                
                rootNode.add(new Label("Annual Interest Rate"), 0, 1);
                rate = new TextField();
                rootNode.add(rate, 1, 1);
                
                rootNode.add(new Label("Number of years"), 0, 3);
                years = new TextField();
                rootNode.add(years, 1, 3);

                futureValue = new TextField();
                futureValue.setEditable(false);
                
                rootNode.add(new Label("Future Value:"), 0, 4);
                rootNode.add(futureValue, 1, 4);                
                
                Button computeButton = new Button("Calculate");
                rootNode.add(computeButton, 0, 5, 2, 1);
                GridPane.setHalignment(computeButton, HPos.CENTER);

                computeButton.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent event) {
                                calculateAndSetValues();
                        }
                });

                myStage.setScene(myScene);
                myStage.show();
        }

        private void calculateAndSetValues() {
                                
                double amount = Double.parseDouble(investment.getText());
                double interestRate = Double.parseDouble(rate.getText());
                double numyears = Integer.parseInt(years.getText());

                double finalAmount = amount * (1 + interestRate/12.0) * numyears * 12;
                
                futureValue.setText("$" + finalAmount);
        }

        public static void main(String[] args) {
                launch(args);
        }
}

please upvote for the efforts i have put for this.

Add a comment
Know the answer?
Add Answer to:
I need help with this code: Write a program that calculates the future value of an...
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
  • Please help me do this program. Add some comments on it. *15.5 (Create an investment-value calculator)...

    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 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,...

  • ***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...

  • 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...

  • 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...

  • 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...

  • 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 =...

  • Posting this again because day limit has run out. Again I really need help with this....

    Posting this again because day limit has run out. Again I really need help with this. This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's and JSP 3rd Edition. The program used is NetBeans IDE 8.2. I need help modifying or adding some code. I will post the code I was told to open that needs to be modified below. Exercise 9-3     Use JSTL to add a table to the Future Value application. In...

  • Hi, Hi, I need someone to write a program in Phython 3.6, and please I will...

    Hi, Hi, I need someone to write a program in Phython 3.6, and please I will appreciate if the code is error free and indented correctly. The output would be preferable. thanks Write a GUI program that translates the Latin words to English. The window should have three buttons, one for each Latin word. When the user clicks a button, the program displays the English translation in a label. 3. Miles Per Gallon Calculator Write a GUI program that calculates...

  • I need help with the following. I need to write a program code in Java using...

    I need help with the following. I need to write a program code in Java using NetBeans. It is from How to Program Java book Chapter 2. This program should calculate the packing of Candles. First read: The number of candles The number of candles that fit in each case Then calculate and print: The number of full cases The number of candles left over (partial case) If this order is large (more than 5 full cases needed) An extra...

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

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