Question: COMP 322 Internet Systems Fall 2014 Assignment 4 25 total points 1 (10 pts.). For this problem, you will maintain an associative array whose keys

COMP 322 Internet Systems Fall 2014 Assignment 4

25 total points 1 (10 pts.). 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.

2 (15 pts.). Write an HTML document prob2.html that loads a JavaScript file prob2.js. The JavaScript program should prompt the user for a string that contains three values separated by any amount of whitespace. There may also be any amount of whitespace (including, in this case, none) before the first value and after the last. The first value on a line should be in a floatingpoint format (explained in detail below), the second value should be a signed or unsigned decimal integer (see below), and the third value should be one of the single letters x, y, or z. You write a regular expression intended to match an entire line (so it begins with ^ and ends with $). Keep running sums of the floating-point numbers represented by the first values and of the integers represented by the second values in a line. Also, maintain a string onto which the third values are concatenated. If one or more of the values in a line are improperly formatted, output that line preceded by the string "No match with "; in this case, the entire line is ignored (making no contribution to the accumulated values). The format for the integer value is simple: either (1) an optional sign followed by a string of digits beginning with a digit other than 0 or (2) the string consisting only of 0. The format for floating-point values is very versatile. There is an optional initial sign. Then, before the decimal point (if there is one), there is either the character 0 or a string of digits beginning with a digit other than 0. There are two possibilities for the remainder. One possibility is a decimal point followed by one or more digits. The other possibility is an optional decimal point and one or more digits, then E or e, and then a string of one or more digits optionally preceded by a sign. The following are examples of valid floating-point representations. 12.34 -3.5 32.2E2 4.23e-10 62E+2 0.0 The following are examples of representations that fail to meet this format. 12.E2 (There is no digit after the decimal point.) 062.42 (The initial 0 is invalid.) The following is the strings that you can use to test your program, which you can download from the assignment site. 12.34 -79 x -3.5 23 y 32.2E2 2 z 4.23e-10 +45 x 62E+2 -4 y 0.0 0 z 12.E2 -125 x 062.42 12987 y 3.45 12.5 z -45.2 06 x COMP 322 Internet Systems Fall 2014 Assignment 4 3 43.6 72 yz -2.63 -10 X The last six lines are invalid. The first two of these six contain the invalid floating-point forms just mentioned. The next two lines contain invalid integer representations (as the second values): 12.5 (not an integer) and 06 (invalid initial 0). The third values in the last two lines are invalid: yz (only single letters are allowed) and X (must be lower case). The following is the output of the program clicking Cancel when prompted for a new string. No match with 12.E2 -125 x No match with 062.42 12987 y No match with 3.45 12.5 z No match with -45.2 06 x No match with 43.6 72 yz No match with -2.63 -10 X 9428.84 -13 xyzxyz To extract the values from the lines, in your regular expression, you will have to do grouping to capture sub-expressions (surrounding sub-expressions to be remembered with parentheses). When you need parentheses for grouping but not capturing, use non-capturing groups, which, recall, are of the form (?:).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!