Question

(4 points) One unrealistic assumption made by our example on compound interest with annual contributions was that the extra a
Write in format where user enters the values in correct underlined formats and write code to match format in example.
Answer quickly and correctly for thumbs up!! thanks!

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

Here is the answer for your question in Java Programming Language.

CODE :

import java.util.Scanner;
public class GettingRichSlowly {
public static void main(String[] args){
//Required variables
double deposit, interestRate, contribution, conRate;
int n;
Scanner s = new Scanner(System.in);

//Reads initial deposit
System.out.print("Enter initial deposit: ");
deposit = s.nextDouble();
//Validates initil deposit
while(deposit <= 0){
System.out.println("\nDeposit value should be greater than 0\n");
System.out.print("Enter initial deposit: ");
deposit = s.nextDouble();
}
//Reads annual interest
System.out.print("Enter annual interest rate (as a percentage): ");
interestRate = s.nextDouble();
//Validates annula interest
while(interestRate <= 0){
System.out.println("\nInterest rate should be greater than 0\n");
System.out.print("Enter annual interest rate (as a percentage): ");
interestRate = s.nextDouble();
}
//Reads number of years
System.out.print("Enter number of years: ");
n = s.nextInt();
//Validates number of years
while(n <= 0){
System.out.println("\nYears should be greater than 0\n");
System.out.print("Enter number of years: ");
n = s.nextInt();
}
//Reads contribution
System.out.print("How much extra would you like to contribute at the end of the first year? ");
contribution = s.nextDouble();
//Validates contribution
while(contribution < 0){
System.out.println("\nContribution should be greater than or equal to 0\n");
System.out.print("How much extra would you like to contribute at the end of the first year? ");
contribution = s.nextDouble();
}
//Reads rate of contribution
System.out.print("How much should the annual contribution increase each year (as a percentage)? ");
conRate = s.nextDouble();
//Validates rate of contribution
while(contribution < 0){
System.out.println("\nContribution Rate should be greater than 0\n");
System.out.print("How much should the annual contribution increase each year (as a percentage)? ");
conRate = s.nextDouble();
}

//Calculates and displays output for given years
for(int i=0;i<n;i++){
double rate = (deposit * (interestRate/100));
double total = deposit + rate + contribution;
System.out.println(String.format("%3d%6s%12.2f%4s%12.2f%4s%12.2f%4s%12.2f",(i+1),"$",deposit,"$",rate,"$",contribution,"$",total));
deposit = total;
contribution = contribution + (contribution*(conRate/100));
}
}
}

SCREENSHOTS :

Please see the screenshots of the code below for indentations of the code.

1 2 3 o 4 import java.util.Scanner; þublic class GettingRichslowly { public static void main(String[] args) { // Required varSystem.out.print(Enter number of years: ); n = s.nextInt(); - } 33 34 35 36 37 38 39 40 41 42 43 //Reads contribution Syste

OUTPUT :

$ run: Enter initial deposit: 100 Enter annual interest rate (as a percentage): 7.5 Enter number of years: 10 How much extra

Any doubts regarding this can be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
Write in format where user enters the values in correct underlined formats and write code to...
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
  • *This question was posted earlier but I want to make sure my code differs from the...

    *This question was posted earlier but I want to make sure my code differs from the other answer* CS50 Assignment 3 and Assignment 4 (Both Due By Sunday March 29 11:59 PM) Assignment 3: Bank Application In a recent lecture, we discussed getting input from the user by using the scanf() function. For your reference, I have included a simple example of using scanf() below: scanf() example: #include int main(void) { int number; printf("Enter a number: "); //prompt the user...

  • This C++ Program should be written in visual studio 2017 You are to write a program...

    This C++ Program should be written in visual studio 2017 You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user...

  • Write a program that prints the accumulated value of an initial investment invested at a specified...

    Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:...

  • Write a program to produce a table that shows the balance of a bank account after...

    Write a program to produce a table that shows the balance of a bank account after each month, assuming that interest is compounded monthly and no additional money is added or withdrawn from the account. Consider this example to understand how this calculation can be done with a loop. Suppose you put $10,000 into an account with an annual percentage rate (APR) of 5.0%. After one month, the account would receive an interest credit of 10000 * 5.0 / 1200....

  • Write a code using loop and flag function in python jupitior notebook: Ask the user for...

    Write a code using loop and flag function in python jupitior notebook: Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe. Ask the user for a number n. Calculate 1+2+3+….+n. Ask the user for a number n. Calculate 1*2*3*…*n. Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns. Ask the user...

  • Your program will ask the user to enter the amount of money they want to borrow,...

    Your program will ask the user to enter the amount of money they want to borrow, the interest rate, and the monthly payment amount. Your program will then determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, your program should notify the user what the...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • please follow the instruction ( very important ) 1912275-dt content-rid 43901523 1/courses/CSct A31. (25 pts) You...

    please follow the instruction ( very important ) 1912275-dt content-rid 43901523 1/courses/CSct A31. (25 pts) You must use a tor loop in the following program Write, compile, debug, and run a program that will use a for loop to do the following Some investments compound interest. This means that the interest is added onto the balance periodically during the year, and the next interest is calculated on this larger balance. This makes the actual return on investment actually greater than...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • (JAVA) Write a program that deals with inflation, which is essentially the rising cost of general goods over time.

    IN JAVAWrite a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years, and the rate of inflation. The output is the estimated...

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