CS152 Fall 2021

Computer Programming Fundamentals
Home
Schedule
Syllabus
Style Guidelines

Assignment 3: Arrays
Due: Friday September 24 by the end of the day (12:00pm)

Description

This assignment focuses on arrays, for loops, and methods. It's challenging! Make sure to get started early and come to office hours early in the week for help.

Write a program that creates a 2D array of random integers between 0 and 100. Your program should prompt the user to enter in a number of rows and then a number of columns and use this information to generate an array of the correct size. The array should then be printed, with each number separated by a tab ("\t").

The program should then print out the following list of things. These results should be calculated by one or more methods in your program:
  • The total number of elements in the array.
  • The largest number in the array.
  • The smallest number in the array.
  • The average of the array
  • The number of elements in the array below 50.
The program should then prompt you to enter in a row and column index and print out the array entry at those indices. If either number you entered is too large to work as an index for the array, your program should print out an error message. Remember that array indices start at 0. See the images below for examples of how your program should behave. Numbers entered by a user are shown in green.

    One execution of the program:


    Another, with an error message:

Your project should also include the appropriate source code header and should follow the course Style Guidelines. You can start from this sample code.

Requirements

Your project should include all of the elements below.

    1. A prompt for the number of rows and columns in the array
    2. A print out of the array where columns are separated by tabs and rows by carriage returns
    3. A print out of the total number of elements in the array
    4. A print out of the largest number in the array
    5. A print out of the smallest number in the array
    6. A print out of the average of all the elements in the array
    7. A print out of the number of elements in the array below 50
    8. A second prompt for a row and column
    9. A print out of the element at that row and column
    10. An error message if either the row or column index given is too large

What to Hand in:

  1. Your program. Like you did for assignment 2, you should upload your .java file to Learn. Name your program using the following convention: FirstnameLastnameAssignment3.java.

  2. A paragraph about your project. In Learn, also submit a paragraph that describes how you wrote your program. Think about your process and explain it: what did you do first, what did you save for last, how did you troubleshoot errors that came up? The paragraph should also discuss any challenges you encountered and describe how you overcame them.