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

CS170 – Computer Applications for Business

Fall 2022 • Assignment 8

Functions, Loops & Arrays

Learning Objectives:

In general, this assignment is designed to practice JavaScript concepts from Chapters 17 top 20 of the textbook. In particular, the following items will be useful for this assignment:

1.  Creating functions

2.  Calling functions

3.  Creating and initializing arrays

4.  Creating and using loops

5.  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:

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

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

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

An Investment Club needs a program to generate a summary report of the investment made by its members.

You are required to implement the interface required using the JavaScript programming language. A GUI screen is not required.

A video of a sample run of this completed assignment is available on the assignment’s webpage on

Canvas.

Inputs needed:

    Number of Members: a numeric value (not greater than 10). The program should produce an error message and terminate if a number greater than 10 is entered.

◦   Per member in the club:

▪   Name: a string

   Investment Amount: a numeric value

Output required:

A Summary Report with the following:

    Smallest Investment: Name and amount of the smallest investment.

    Largest Investment: Name and amount of the largest investment.

    Total Investment: Total Amount invested by the club as a group.

    Average Investment: Average Investment per member.

    Projected Growth: In % terms (a number between 0% and 100%.), generated by a random number .

    Projected Earnings per Member: In $ amounts, based on the projected growth (projected growth % multiplied by investment). It should list the name and projected earnings for each member.

Additional Notes:

    Use the prompt function to gather the inputs.

    The document.write function should be used heavily to generate the Summary Report.

NOTE: The projected growth and earnings part of the Summary Report will produce different results each time the program runs due to the use of a random number.

Requirements :

Arrays:

    Use two parallel arrays to hold the information related to the names and investments per member.

Functions

    Functions are required to:

    Calculate the Smallest Investment

    Calculate the Largest Investment

    Calculate the Total Investment

    A function is also required to generate the projected earnings per member.

    Tip: Use a loop to process the elements of the arrays.

SAMPLE TEST DATA and RESULTS

Sample Data

Inputs:

 

Name

Investment

(numbers in thousands)

20

Mary

10

30

Outputs:

Smallest

Investment :

Mary, $10

Largest

Investment:

Paul, $30

Total

Investment:

Average

Investment:

$60

$20

Projected

Growth:

47%

Projected

Earnings per

Member:

John: $9.40

Mary: $4.70

Paul: $14.10

Sample Summary Report (the projected growth and earnings part of the report will produce different results each time the program runs):

 

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:

x = prompt(“Enter some number”);

x = Number(x);

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

someNumber.toFixed(2)

   To simplify the comparison of text data entered by the user, it is often easier to convert this text to upper case using the notation below. Syntax example:

textVariable = textVariable.toUpperCase();

   To enter the date on the report use the syntax: var d = new Date(); which captures current Date/Time on the d variable.

Point Values

Student name inserted as comment in the head section

1

Variable declarations and initializations

1

Screen Flow

2

Inputs

2

Outputs

2

Arrays

3

Loops

3

Functions

3

IF statements

3

Program execution

5

References:

    Recitation sessions

    Lectures

    Fluency textbook Chapters 17 to 20

   JavaScript Reference Guide