Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an algorithm in pseudocode and a program to settle the following question. A bank account starts out with an initial balance. Interest is

image text in transcribed 

Write an algorithm in pseudocode and a program to settle the following question. A bank account starts out with an initial balance. Interest is computed monthly at 6% per year (0.5% per month). Every month $500.00 is withdrawn to meet education expenses. After how many years and months the account depleted? Write a Java program to prompt user for initial balance, and find how many years and month takes until the account dpleted. There are some values for which the algorithm you developed may not terminate (why?). Modify your algorithm to make sure it always terminates. Sample run of the program for different initial balance: 6 years and 1 month 1 year and 6 months 8 months (note that the output should not be as 0 years and 8 month) Notes: 1. Expenses are Withdraw at the end of each month. For example if the initial balance is equal to 500$, then at the end of the first month the balance will be equal to 500*(1+0.06/12) = 502.50 After taking 500$ for expenses, the balance will be equal to 2.50. At the end of the second month the balance will be equal to 2.51, and this is the maximum amount the account owner can use. As the result it takes two months to deplete the account. The output of the program in this case will be: 2 months 2. A magic number is basically a hard-coded value that might change at a later stage. Since it has the chances of changing at a later stage, it can be said that the number is hard to update. The use of magic numbers in programming refers to the practice of coding by using particular numbers directly in the source code. This practice isn't recommended in programming and is considered to be a breakage of one of the oldest rules of programming. For example, 500$ and 6% are magic numbers. Avoid magic numbers in your code. Instead of hard coding these numbers into your code, either use a variable or declare them as constants. For example use double withdraw = 500; double interestRatePerMonth = 0.06/12; or use them as constant: final static double WITHDRAW = 500; final static double INTEREST_RATE_PER_MONTH = 0.06/12; and use them in your code. Assembling output message: You can assemble the output by attaching strings to each other. Compile and run the following program for different values of variable candy. Based on the value of candy, the message is generated and displayed on the console. You should use similar method to generate output of your program. public class Message { } public static void main (String[] args) { int candy = 6; String msg = ""; msg = candy + "cand"; if (candy> 1) } msg msg + "ies"; else msg = msg + "y"; System.out.println(msg);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Below is the pseudocode for the algorithm to determine how many years and months it takes until the ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Concepts Late Objects

Authors: Cay S. Horstmann

3rd Edition

1119186714, 978-1119186717

More Books

Students also viewed these Programming questions