Question

In: Computer Science

Modify the RetirementGoalapplication to display the amount of money the user will have if the user...

Modify the RetirementGoalapplication to display the amount of money the user will have if the user earns 4%interest on the balance every year. In java pls

given code.

import java.util.Scanner;
public class RetirementGoal2
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
int years;
int saveAmount;
int total;
final double RATE;

// perform interest calculation
System.out.print("How many years until retirement? >> ");
years = input.nextInt();
while(years <= 0)
{
System.out.println("Years cannot be 0 or negative");
System.out.print("Please renter years >> ");
years = input.nextInt();
}
System.out.print("How much can you save annually? >> ");
saveAmount = input.nextInt();
while(saveAmount <= 0)
{
System.out.println("Amount cannot be 0 or negative");
System.out.print("Please renter amount to save annually >> ");
saveAmount = input.nextInt();
}
total = saveAmount * years;
System.out.println("If you save $" + saveAmount +
" for " + years + " years without interest, you will have $" + total);
double total2 = 0;
for(int y = 0; y < years; ++y)
{
total2 += saveAmount;
}
System.out.println("If you save $" + saveAmount +
" for " + years + " years, with " + (RATE * 100) +
"% interest, you will have $" + total2);
}
}

Solutions

Expert Solution

import java.util.Scanner;

public class RetirementGoal2 {
        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                int years;
                int saveAmount;
                int total;
                final double RATE = 0.04;

                // perform interest calculation
                System.out.print("How many years until retirement? >> ");
                years = input.nextInt();
                while (years <= 0) {
                        System.out.println("Years cannot be 0 or negative");
                        System.out.print("Please renter years >> ");
                        years = input.nextInt();
                }
                System.out.print("How much can you save annually? >> ");
                saveAmount = input.nextInt();
                while (saveAmount <= 0) {
                        System.out.println("Amount cannot be 0 or negative");
                        System.out.print("Please renter amount to save annually >> ");
                        saveAmount = input.nextInt();
                }
                total = saveAmount * years;
                System.out.println(
                                "If you save $" + saveAmount + " for " + years + " years without interest, you will have $" + total);
                double total2 = 0;
                for (int y = 0; y < years; ++y) {
                        total2 = (saveAmount + total2) * (1 + RATE);
                }
                System.out.println("If you save $" + saveAmount + " for " 
                + years + " years, with " + (RATE * 100)
                                + "% interest, you will have $" + total2);
        }
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money...
1. [10 marks] (Changes.java) Write code that asks the user to enter an amount of money from 0 to 99 cents. The program then calculates and displays the number of coins from each denomination: quarters (25 cents), dimes (10 cents), nickels (5 cents), and cents. For example, if the user enters 93, your program should display There are 3 quarters, 1 dimes, 1 nickels, and 3 cents in 93 cents Note: You must use integer division and modular division to...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
C Programming Please modify this code to display the "guess" value from the calculation and the...
C Programming Please modify this code to display the "guess" value from the calculation and the "iterations" it took to complete. Please also add the input to the program. Input: Program will prompt the user to provide the desired decimal-place accuracy, in the range of [1-15], inclusive. User prompt must clearly indicate what is a valid input. User input must be validated - ensuring that the value entered is an integer in the above range. Sample output for one perfect...
Write a program that prompts the user for their first and lastname. Display the first...
Write a program that prompts the user for their first and last name. Display the first initial of their first name and their last name to the user.Ask the user to input a phone number.The program checks which part of Colorado a phone number is from using the values below.If the second digit of the phone number is one of the below digits, print the phone number and which part of Colorado it is from. If none of the digits...
Write the code (in a function) that allows the user to display the first “nb” of...
Write the code (in a function) that allows the user to display the first “nb” of elements in the Fibonacci sequence (each value on a separate line in the console). The order of the Fibonacci sequence goes as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 and on to infinity. Each number is the sum of the previous two (with the 2 starting numbers being 1 and 1). This series of numbers is known as...
In c++, modify this program so that you allow the user to enter the min and...
In c++, modify this program so that you allow the user to enter the min and maximum values (In this case they cannot be defined as constants, why?). // This program demonstrates random numbers. #include <iostream> #include <cstdlib> // rand and srand #include <ctime> // For the time function using namespace std; int main() { // Get the system time. unsigned seed = time(0); // Seed the random number generator. srand(seed); // Display three random numbers. cout << rand() <<...
Modify the Tip Calculator app to allow the user to enter the number of people in...
Modify the Tip Calculator app to allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members. Code: ----------------TipCalculator.java----------------------- import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class TipCalculator extends Application { @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("TipCalculator.fxml")); Scene scene = new Scene(root); // attach scene graph to scene...
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
Calculate the amount of money that a person must have in a bank today (the beginning...
Calculate the amount of money that a person must have in a bank today (the beginning of the year) to be able to withdraw $375 at the end of each year for the next 10 years if the bank pays interest compounded yearly at j1 = 5.8% pa. Give your answer in dollars and cents to the nearest cent. Account balance = $ Calculate the simple interest rate pa that must be earned for $60,000 invested on 29 October 2019...
Q1) Modify the following code to sequentially display 154628577990449700 /* DisplayDigitsUsingIndexedArray - Sequentially displays digits 0...
Q1) Modify the following code to sequentially display 154628577990449700 /* DisplayDigitsUsingIndexedArray - Sequentially displays digits 0 - 9 using an indexed array and register I/O Written by Duncan McGehee 1 October 2011 */ /*PORTD.7 is connected to the A-segment of the 7-segment display PORTD.6 = B, PORTD.5 = C, PORTD.4 = D, PORTD.3 = E PORTD.2 = F, PORTD.1 = G */ /* Declare an array of binary numbers that will be used to drive the 7-segment display. This is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT