Question

In: Computer Science

how do i program this to Java: Company X offers a 401k (Links to an external...

how do i program this to Java:

Company X offers a 401k (Links to an external site.) retirement plan that allows you to save a percentage of your salary every year.

Your investment will grow using a flat interest rate that you will provide as input.

The goal is to compute how much money you will have for retirement after a specified number of years.

This is just a basic calculation. No loops yet!

Input

Read the following from input. Make sure you prompt for input.

Salary - your salary will remain the same for all of your years of employment. Read in as int.

Percentage of Salary you will save for retirement each year. Read in as double so 6% = .06.

Interest Rate - the rate at which your retirement plan grows over the duration. Read in as double so 5% interest rate = .05.

Employment Years - the number of years you will work at Company X. Read in as int.

For the interest formula, just use the below:

Total Savings = Years of Employment * Percentage of Salary you save * Salary * (1 + Interest Rate)

Output

Your input variables as well as the amount you will have saved in retirement.

Please prompt the user. Include a line that says please enter in your salary percentage saved interest rate and employment years separated by a space.

Sample Run

Enter input: salary savings_rate interest_rate years_employed
> 70000 .10 .06 30
Salary: 70000
Savings rate:0.1
Interest rate:0.06
Years of Employment: 30
Retirement Savings: 222600.0

Solutions

Expert Solution

// Java program to calculate the retirement savings after a specified number of years for the given interest rate and percentage of salary saved

public class RetirementSavings {
   public static void main(String[] args) {
  
       double savings_rate, interest_rate ;
       int salary, years_employed;
      
       Scanner scan = new Scanner(System.in);
       // Input of salary, percentage of salary saved, interest rate and years employed
       System.out.print("Enter input: salary savings_rate interest_rate years_employed : " );
       salary = scan.nextInt(); // read the salary
       savings_rate = scan.nextDouble(); // read the percentage of salary saved
       interest_rate = scan.nextDouble(); // read the interest rate
       years_employed = scan.nextInt(); // read the years employed
      
       // calculate retirement savings
       double retirement_savings = years_employed * savings_rate*salary * (1+interest_rate);
      
       // output
       System.out.println("Salary: "+salary);
       System.out.println("Savings rate: "+savings_rate);
       System.out.println("Interest rate: "+interest_rate);
       System.out.println("Years of Employment: "+years_employed);
       System.out.println("Retirement Savings: "+retirement_savings);
      
       scan.close();
   }
}

//end of program

Output:


Related Solutions

Read Small Business Expert: How Do You Find and Pick a Lawyer (Links to an external site.)Links to...
Read Small Business Expert: How Do You Find and Pick a Lawyer (Links to an external site.)Links to an external site., by Basha Rubin, Forbes' contributor Read the Forbes' Small Business Expert: How Do You Find and Pick a Lawyer (assignment 3), and then participate in this forum: -  Discuss what you learned from the reading. -  Provide three specific recommendations that you would make to a friend who is starting a new business and looking for an attorney.
This is a statistics calculator and simulator (Links to an external site.). For this assignment, I...
This is a statistics calculator and simulator (Links to an external site.). For this assignment, I would like you to start with a real life scenario in which you might need to know some statistical measures. Provide a real life scenario (you must have 10 numbers with a frequency of 1 and calculate the statistics) Take a screenshot of the completed stats. Now, change your frequencies to anything you want and see how the data changes. Take a screen shot...
Comeputer science .This is java problem. PROBLEM 1 Queue (Links to an external site.) is an...
Comeputer science .This is java problem. PROBLEM 1 Queue (Links to an external site.) is an abstract data type (ADT) consisting of a sequence of entities with a first-in-first-out (FIFO) (Links to an external site.) property. Queue has the following operations, in alignment with the Java Queue interface (Links to an external site.) in the Oracle's SDK: add(x): inserts the specified x element to the back of queue without violating capacity limitation. remove(): removes the head (front) of queue, returning...
How do the Bill of Rights (Links to an external site.) protect non-violent direct action of...
How do the Bill of Rights (Links to an external site.) protect non-violent direct action of US citizens?
c++: I need #include <iostream> header A palindrome (Links to an external site.) is a word,...
c++: I need #include <iostream> header A palindrome (Links to an external site.) is a word, phrase, number, or sequence of words that reads the same backward as forward. Punctuation, capitalization, and spaces between the words or lettering are allowed. Here are some examples of word and phrase palindromes. Words: Civic Kayak Level Madam Mom Noon Racecar Radar Refer Rotor Phrases: Don't nod. I did, did I? My gym Step on no pets Top spot Never odd or even Eva,...
In a Java program, how could I write a program that can assign values that would...
In a Java program, how could I write a program that can assign values that would make a rock paper scissors game work? I have a program that will generate a computer response of either rock, paper, or scissors but how can I compare a user input of "rock", "paper", or "scissors" so that we can declare either the user or the computer the winner.
How can I write java program code that do reverse, replace, remove char from string without...
How can I write java program code that do reverse, replace, remove char from string without using reverse, replace, remove method. Only string method that I can use are length, concat, charAt, substring, and equals (or equalsIgnoreCase).
1A. Explain how histograms (Links to an external site.) are used to examine data. Describe the...
1A. Explain how histograms (Links to an external site.) are used to examine data. Describe the various shapes of histogram and their meaning. 1B. When would it be appropriate to use a histogram as opposed to a scattergram? 1C. What is the purpose of a Data Dashboard? If you were the manager of a restaurant, for example, what 5 key metrics would you want to display on a Data Dashboard? (note: You should think about what important metrics a company,...
1. Explain how histograms (Links to an external site.) are used to examine data. Describe the...
1. Explain how histograms (Links to an external site.) are used to examine data. Describe the various shapes of histogram and their meaning. 2. When would it be appropriate to use a histogram as opposed to a scattergram? 3. What is the purpose of a Data Dashboard? If you were the manager of a restaurant, for example, what 5 key metrics would you want to display on a Data Dashboard? (note: You should think about what important metrics a company,...
Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I...
Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I filter out all links with Twitter domains and shortened links?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT