Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: (10 pts.) Tiny Bank For this problem, you will maintain an associative array whose keys are people's names. An associated value is an

image text in transcribed

Part 2: (10 pts.) Tiny Bank For this problem, you will maintain an associative array whose keys are people's names. An associated value is an object with three properties: deposits (an array of the person's deposits), withdrawals (an array of the person's withdrawals), and balance (the person's current balance). We assume that an account starts out with a zero balance so that the current balance is the sum of the deposits minus the sum of the withdrawals. Write an HTML document prob2.html that loads a JavaScript file prob2.js. When the body is finishes loading, function go () s called. The body of the document consists of an empty div element with id value recs" Function go () in prob2.js first calls function init), which prompts for names until the user clicks Cancel. Each name becomes a key in an associative array, and the associated value is an object with its deposits and withdrawals properties initialized to [1, and its balance property initialized to 0. It returns this associative array, which is assigned to, say, recs in go () Function go ) next calls update (), passing it recs. This function loops through round after round as long as the user clicks OK (not Cancel) in the confirmation box asking about another round. In each round, the function loops over all the names of people. For each person, it asks for their deposit and their withdrawal for that round. The user enters "O" if no deposit or no withdrawal was made. As long as the deposit is not "O", it is added to the end of the array that is the value of the deposits property; similarly, the withdrawal is added to withdrawals. (An easy way to add something to the end of an array is to use the array's push () method. If ar is an amay and x is some value, ar, push (x) adds x to the end of ar. ncreasing its length by 1.) The person's balance is also updated each round. Finally, go ) calls outRecs), passing it recs. This function assigns to, say, recsRef a reference to the div element (with id "recs"). Its constructs in, say, recstr a string with all the information in associative array recs, and this string is assigned to the innerHTML property of recsRef. For each element of recs, the string has one line with the name followed by a ':'. The next three lines have, respectively, the array of deposits, the array of withdrawals, and the balance for the person named. Each of these three lines begins with two spaces. (Use the character entity reference to have the browser insert a space.) Use the tostring ) method of the arrays of deposits and withdrawals to get a quick string representation of the contents of these arrays; do not spend time on appearances. (The contents of these arrays will be strings that have not been converted to numbers. These strings are converted to numbers when the balance is updated since that involves subtraction.) The screenshot at right shows the output when names "Al" and "Ed" were supplied, and the update went through two rounds. In the first round, Al deposited 5.50 and withdrew 3.20 while Ed deposited 3.00 and withdrew nothing. In the second round, Al deposited 5.20 and withdrew 4.10 while Ed neither deposited nor withdrew Al: Deposits: 5.50,5.20 Withdrawals: 3.20,4.10 Balance: 3.40 Ed Deposits: 3.00 Withdrawals Balance: 3.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago