Question

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 in the displayInstructions method. Then the user will be prompted within the main method to input the monthly investment, the number of months of the investment, and the annual interest rate. You will be asking the user for the annual interest rate as a decimal (like 0.03), however, you will be calculating the monthly interest rate by dividing that annual rate by 12 (number of months in a year). That calculation will take place in the main method, prior to sending the monthly interest rate to the static method that will do the future value calculation. The name of the static method that will display the instructions, will be called displayInstructions. The name of the static method that will return the future value of the investment, will be called calculateFutureValue. The first static method will be a void method. It will not return any value. It will simply display the instructions using the familiar System.out.println(). The second static method will be passed (from the main method) the amount of monthly investment (the same for every month), the monthly interest rate (calculated from the annual interest rate annual interest rate divided by 12, in the main method), and the number of months of the monthly investments will be made. This static method will return the futureValue to the main method. You will need to have a variable set up in the main method to receive that returned value. See the Static Method Practice C4PE sheet for how that is done. The calculation of the future value will take place in a for loop where the counter (use i) will start at 1 and loop for the number of months passed to the method. Each time through the loop, you will use the following calculation: futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate); Notice that the variable futureValue is used on both sides of the equal sign. The is so that futureValue is added to the amount previously calculated in the prior loop each time. So this acts as an accumulator and calculates the new month’s interest on the new total. Look at that expression carefully, and make sure you understand how it works. Test your program with several numbers to ensure that it performs as it should.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// FutureValue.java

import java.util.Scanner;

public class FutureValue {

      public static void main(String[] args) {

            // scanner to read user input

            Scanner scanner = new Scanner(System.in);

            // displaying instructions

            FinancialUtils.displayInstructions();

            // asking and receiving inputs

            System.out.print("\nEnter monthly investment: ");

            double amount = scanner.nextDouble();

            System.out.print("Enter annual interest rate: ");

            double annualIntRate = scanner.nextDouble();

            System.out.print("Enter number of months: ");

            int months = scanner.nextInt();

            // finding monthly interest rate

            double monthlyIntRate = annualIntRate / 12.0;

            // calculating future value

            double futureValue = FinancialUtils.calculateFutureValue(amount,

                        monthlyIntRate, months);

            // displaying it with a precision of two digits after decimal point

            System.out.printf("\nThe future value will be $%.2f", futureValue);

      }

}

// FinancialUtils.java

public class FinancialUtils {

      // method to display the instructions

      public static void displayInstructions() {

            System.out

                        .println("==============================================================="

                                    + "\nThis program calculates the future value of an investment\n"

                                    + "given the monthly investment, annual interest rate (in decimal)\nand "

                                    + "number of months\n"

                                    + "===============================================================");

      }

      // method to calculate and return the future value, given monthly

      // investment, monthly interest rate and number of months

      public static double calculateFutureValue(double monthlyInvestment,

                  double monthlyInterestRate, int numMonths) {

            double futureValue = 0;

            // using a for loop, calculating the future value using the equation

            // provided in the question

            for (int i = 1; i <= numMonths; i++) {

                  futureValue = (futureValue + monthlyInvestment)

                              * (1 + monthlyInterestRate);

            }

            // returning final value

            return futureValue;

      }

}

/*OUTPUT*/

===============================================================

This program calculates the future value of an investment

given the monthly investment, annual interest rate (in decimal)

and number of months

===============================================================

Enter monthly investment: 1250

Enter annual interest rate: 0.075

Enter number of months: 24

The future value will be $32460.02

Add a comment
Know the answer?
Add Answer to:
CIT 149 JAVA 1 programming question? There will be two files for this problem. The first...
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...

  • 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();            ...

  • CIT 149 Java 1 programming question Use DrJava to compile the following try-catch program ? The...

    CIT 149 Java 1 programming question Use DrJava to compile the following try-catch program ? The Assignment ? Specifications General Structure your file name and class name on the following pattern: The first three letters of your last name (begin with upper case.). Then the first two letters of your first name (begin with upper case.). Follow this with the name of the program: TryCatch. For a student called ’John Doe,’ the class name and file name would be: DoeJoTryCatch...

  • 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 public class for java. Thank you. 1. (10 points) Write a method that computes...

    Please use public class for java. Thank you. 1. (10 points) 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 formula futurelnvestmentValue numberOfYears 12 investmentAmount X ( monthlyInterestRate) Use the following method header: public static double futurelnvestmentValue( double investmentAmount, double monthlyInterestRate, int years) For example, futureInvestmentValue 10000, 0.05/12, 5) returns 12833.59. Write a test program that prompts the user to enter the investment...

  • solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate...

    solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...

  • JAVA PROBLEM #1: The British have been shelling the Revolutionary forces with a large cannon from...

    JAVA PROBLEM #1: The British have been shelling the Revolutionary forces with a large cannon from within their camp. You have been assigned a dangerous reconnaissance mission -- to infiltrate the enemy camp and determine the amount of ammunition available for that cannon. Fortunately for you, the British (being relatively neat and orderly) have stacked the cannonballs into a single pyramid-shaped stack. At the top is a single cannonball resting on a square of 8 cannonballs, which is itself resting...

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

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

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
Active Questions
ADVERTISEMENT