Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CS170 – Computer Applications for Business

Fall 2021 Assignment 8

Loops & Arrays


Learning Objectives:

This assignment is designed to practice:

1. Creating functions

2. Calling functions

2. Creating and initializing arrays

3. Creating and using loops

4. Using Number() function to ensure values are treated as numbers and not strings

6. Using concatenation to add currency or percent symbols

7. Using toFixed(2) method to round to 2 decimal places

8. Reading and understanding the use of comments


To earn credit for this assignment:

You will create JavaScript code – embedded on an HTML file - according to the requirements listed on the next pages.

Upload and submit a single html file (.html extension) containing the code required.

A video of a sample run of this completed assignment is available (see the References section of this document).

For your assignment to be graded, please include the following statement as a comment in the <head> section of the program:

“ On my honor, I have neither received nor given any unauthorized assistance on this assignment.”


PROBLEM DESCRIPTION

A Movie Theater company requires a program to process the box office receipts of its movie theaters. It wants a screen that allows the user to enter a movie theater name and the revenues for the last three weeks. A Process button will be used to display the total result of those revenues. In addition, a Report button will be used to generate a summarty report for all the revenues entered for the movie theaters.

You are required to implement the interface required using the JavaScript programming language. The illustration below displays the GUI screen required. A template is provided to you with the basic structure of the interface.

Note: Choose a background color and a text color of your preference.


Requirements:

Arrays:

● They will be used to record the theater name, the revenues for week 1, 2 and 3 as well as the theater total.

● Therefore, five arrays need to be declared inside the <script> section of the program (the <script> section should be placed inside the <head> section):

theaterArray: an array to hold the names of the theaters (size 10).

 week1Array: an array to hold the Week 1 data for the theaters entered (size 10).

week2Array: an array to hold the Week 2 data for the theaters entered (size 10).

week3Array: an array to hold the Week 3 data for the theaters entered (size 10).

totalArray: an array to hold the total revenue for the theaters (size 10).

● The input for the first theater should be stored in the first element of the theaterArray, week1Array, week2Array, week3Array. The total for the first theater should be stored on the first element of the totalArray.

● The input for the second theater should be stored in the second element of the theaterArray, week1Array, week2Array, week3Array. The total for the second theater should be stored on the second element of the totalArray.

● In a similar fashion, the data of the third theater will be stored in the third elements of the arrays mentioned. The same for any additional theater.

● Therefore, the concept of parallel arrays is being used: the first elements of the arrays belong to the first theater, the second elements of the arrays belong to the second theater, etc.


Functions

Creating the functions

● Functions are required to initialize the arrays.

A function to initialize a text array (array whose elements will be strings). This function will be used to initialize the arrays that will contain destinations and air travel options.

● Tip: Use a loop to initialize the elements of an array with empty strings.

Another function to initialize numeric arrays. This function will be used to initialize the arrays that will contain prices for each customer.

Tip: Use a loop to initialize the elements of an array with zeros.

● They will require only one parameter for each of them. The argument passed to this parameter will be an array.

● One function is required to add up the totals stored in the totalArray.

● Tip: Use a loop to add up the elements of the array.

● They will require only one parameter for each of them. The argument passed to this parameter will be an array.

The function definitions should be added inside the <script> section of the program. This <script> section should be placed inside the <head> section.


Calling the functions

● The initialization functions should be called inside the <script> section of the program.

● Call once the function that initializes text arrays:

● with the theaters array as argument.

● Call four times the function that initializes numeric arrays.

● with the week1 array as argument.

● with the week2 array as argument.

● with the week3 array as argument.

● with the total array as argument.

● Call the function that adds up elements of an array when generating the report.


Buttons:

Process button:

● it is clicked on to process a single theater.

● It will take care of the following tasks:

It will calculate the total revenue for the theater entered (the sum of revenues for Week 1, 2 and 3).

It will display the total revenue on the output text box.

It will store the name of the theater, revenues for Weeks 1, 2 and 3 as well as the total revenue in the corresponding elements of the arrays created.

○ It will update the index variable used by the arrays.


Generate Report button:

● The Generate Report button will produce a small Summary Report with the grand total for all theaters as well as the average total per theater.

● It will be clicked on once after the data for the movie theaters has been entered and processed.


SAMPLE TRACE THROUGH THE CORRECT ALGORITHM


Report

Total Revenue for all theaters: 160

Average Revenue per theater: 53.33


Additional Information:

● Be sure to include a comment with your name and section in the <head> part of your HTML code program.

● Since the content of a text box which requires a number may be used in mathematical operations, use the function Number() to ensure that the numeric input is treated as numeric data. Syntax example:

numericVariable = Number(myBoxID.value)

● Syntax example to round up a number to 2 decimals. Just add .toFixed(2) to the variable name containing the number.

someNumber.toFixed(2)

● You will use several variables in this program.