Write an algorithm in pseudocode and a program to settle the following question. A bank account...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 dépleted. 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); 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 dépleted. 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);
Expert Answer:
Answer rating: 100% (QA)
Below is the pseudocode for the algorithm to determine how many years and months it takes until the ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Class Median Midpoint, x Income, I 19.5 $12,965 An individual's income varies with age. The table shows the median income I of individuals of different age groups within the United States for a...
-
In the same example, how would you change your answer if you discovered that the probability of "up" were 0.1, so that the exchange rate looked grossly overvalued?
-
Find Taylor series at x = 0 for the function. 1 1 + x
-
Nationwide Insurance developed a program to recruit new insurance agents by offering planning, training, and start-up financing to build self-sustaining agencies. These new agents would be...
-
Holiday Fruit Company buys oranges and processes them into gift fruit baskets and fresh juice. The company grades the fruit it buys on a scale from 1 (lowest quality) to 5 (highest quality). The...
-
1. Convert the following iteration Even method to recursive method: (Ex: EVEN(0,10) Void enas iteration even(int Lint n) { } int i=1: while(i
-
There is a parcel of land next to the Playful Paws, Inc. building. Ellen, the owner of this property, approached John to discuss the idea of selling it to him. John is interested. Ellen knows that...
-
You are building airplanes. Because it takes a long time to build a plane, you make your output decisions before the demand information is actually revealed. The best prediction of what the demand...
-
Which appraisal approach is used to determine the value of property by comparing sales of other similar properties?
-
What is geniune saving ? what is total funding avaialble ? In this task, you are required to balance the funding position below to meet the needs and requirements of Natasha. Funds Needed Funds...
-
The figure shows a 24.0 V battery connected to four uncharged capacitors of capacitances C = 2.00 F, C = 4.00 uF, C3 = 6.00 uF, and C4 = 8.00 F. C C3 Sq C2 C4 S F B Switch S is closed. Switch S is...
-
Using Python , create a GUI that calculates your wealth at retirement given the following inputs into the GUI 1) Mean Return (%) This is the average annual return of the investment above inflation 2)...
-
Capital structure is an important business decision for a finance manager. Discuss the following points related to the capital structure of a business: What is capital structure, and how it is...
-
4.) Write the equation of the line perpendicular to the line -x+2y = 12 that goes through the point (10, 8). Show all work.
-
You are a Loan Officer with an Investment Bank. Today you need to set your lending parameters. They are: LTV: 55% 10 Year T-Bill: TBD Rate Markup: 300 Basis Points Term: 30 Years Amortization: 30...
-
Write a method that computes the average of the neighbors of a two-dimensional array element in the eight directions shown in Figure 14. public static double neighborAverage(int[][] values, int row,...
-
What do these code snippets print? a. int result = 0; for (int i = 1; i
-
True or false? a. All elements of an array are of the same type. b. Arrays cannot contain strings as elements. c. Two-dimensional arrays always have the same number of rows and columns. d. Elements...
-
Redo the preceding exercise, this time using the mathematics scores. Preceding Exercise Use the reading comprehension data in Exercise 6.18 to test the null hypothesis that the population mean of X...
-
What type of accounts are accounts receivable and inventory? (a) Cash accounts. (b) Operating accounts. (c) Financing accounts. (d) Investing accounts.
-
Which of the following is a cash outflow? (a) Proceeds from borrowing. (b) Repayments of debt principal. (c) Payment for taxes. (d) Both (b) and (c).
Study smarter with the SolutionInn App