Question

In: Computer Science

Write a program that will accept user input for an initial deposit and a total amount...

Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%.

Solutions

Expert Solution

import java.util.Scanner;

public class AccountDeposit {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
//       user input for an initial deposit  
//       user will deposit the initial amount in a new account
       System.out.print("Enter an initial deposit :");
       double principle = sc.nextDouble();
//       total amount the user wants to have
       System.out.print("Enter a total amount the you wants to have :");
       double totalAmount = sc.nextDouble();
      
       double time = 0;
//       the account will receive interest, compounded MONTHLY, at a rate of 0.5%.
       double rate = 0.5;
       int yearsCount = 0;
          
       while(true)
/* Calculate compound interest */
{
           double CI = principle * (Math.pow((1 + rate / 100), time));
           if(CI+principle>=totalAmount) break;
           time++;
}
//       the number of years it will take to reach his/her goal
       System.out.println("The number of years it will take to reach your goal is "+(int)(time/12));
  
   }
}


Related Solutions

Write a program that will accept user input for an initial deposit and a total amount...
Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%. Then modify it by allowing the user to set a fixed amount to be deposited into...
JAVA Write a program that will accept user input for an initial deposit and a total...
JAVA Write a program that will accept user input for an initial deposit and a total amount the user wants to have, and will output the number of years it will take to reach his/her goal. For the basic program, the user will deposit the initial amount in a new account, and then the account will receive interest, compounded MONTHLY, at a rate of 0.5%.
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Write a program in pyton with total change amount as an integer input, and output the...
Write a program in pyton with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes Can you...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a program with total change amount as an integer input, and output the change using...
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes c++ please
Write a program to ask the user to en ter the total amount spent at best...
Write a program to ask the user to en ter the total amount spent at best buy before taxes. Assuming the sales tax applied is 5.7%, display the total amount after taxes and the amount added by the sales tax. Be sure to document your program (add comments) . C++ program
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT