Question: For this problem, you will maintain an associative array whose keys are peoples custName. An associated value is an object with three properties: accounts (an
For this problem, you will maintain an associative array whose keys are peoples custName. An associated value is an object with three properties: accounts (an array of a customers accounts objects), address (string literal, with just the city name), salary (the customers current salary) and loans (an array of a customers loan objects). We assume that a customers salary can start out with a zero. Write an HTML document prob1.html that loads a JavaScript file prob1.js. When the body is finishes loading, function go() is called. The body of the document consists of an empty div element with id value "custs". Function go() in prob1.js first calls function customer(), which prompts for the customers name. Each name becomes a key in an associative array, custs, and the associated value is an object with its accounts property initialized to [], loan property initialized to [], the address property initialized to an empty string and its salary property initialized to 0. Remember that the accounts property is an object with several properties, therefore a function account () is needed. This method should prompt the user for the accounts acctName and balance as account associative pair and then adds the account object to the array. The account () should prompt the user for more accounts until the user clicks Cancel. The customer()should continuously prompting the user more customers until the user clicks Cancel. You are limited to using Savings and Checking accounts name. Function go() next calls approveLoan(). This function prompts the user for a name a of customer that needs a loan then the name of the loan and the loan amount (> 0.0). If the name of the customer is not in the associative array for the customer, the user should be re-prompt saying user does not exist. Otherwise, approaveLoan () should loop through all the customers accounts for the account balances, each account balance should be added to customers salary then compared to the loan amount. If the loan amount is 3 times less than the salary + account balances, then approve the loan, otherwise disapprove the loan. The approaveLoan () should continuously prompting the user more names until the user clicks Cancel. You should store the loan name and amount as a pair in the loan property for the customer, with a status that says approved/disapproved. Special situation, if the customer already has any loans, loop through the loan array and add the loan amounts for that customer. Use the approved loans + the salary + total account balances to determine if the new loan should be approved or not. Finally, go() calls outCusts(), passing it custs. This function assigns to, say, custsRef a reference to the div element (with id " custs"). Its constructs in, say, custsStr a string with all the information in associative array custs, and this string is assigned to the innerHTML property of custsRef. For each element of custs, the string has one line with the name followed by a :. The next four lines have, respectively, the address, the salary, the array of accounts, the array of loans. Each of these four 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 accounts and COMP 322 Internet Systems Fall 2014 Assignment 4 2 loans 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 above shows the output when names Jill and Jane customer records were created.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
