ITSC121S2020Lab9

From BU Computer Science
Jump to navigation Jump to search

Ninth Programming Lab, ITSC 121, Spring 2020

Overview

Write the following programs. The first one deals payroll. The second deals with searching

Program 1: Payroll (edited problem 8.4)

Suppose the weekly hours for all employees are stored in a 2-dimensional array. Each row records an employee's seven-day hours with seven columns. For example, the following array stores the work hours for eight employees. Write a program that displays employees and their total hours. For extra credit, display the total hours in decreasing order. Use -1 to indicate the end of data. You must use a 2D array to store the data before doing any computations.

               Su  M  T  W  Tu F  Sa
Employee 0      2  4  3  4  5  8  8
Employee 1      7  3  4  3  3  4  4
Employee 2      3  3  4  3  3  2  2
Employee 3      9  3  4  7  3  4  1
Employee 4      3  5  4  3  6  3  8
Employee 5      3  4  4  6  3  4  4
Employee 6      3  7  4  8  3  8  4
Employee 7      5  3  5  9  2  7  9

Results: (for extra credit)
7   41 hours
6   37 hours
0   34 hours
4   32 hours
1   28 hours
5   28 hours
3   21 hours
2   20 hours

Results for full credit:
34
28
20
21
32
28
37
41

The input would just be the numbers with a -1 indicating the end of data (a set of 7 -1's would also be okay)

Program 2: Searching (adapted problem 8.13)

Write the following method that returns the location of the largest element in a 2-dimensional array:
public static int[] locateLargest(double[][] a)
The return value is a one dimensional array that contains two elements. These two elements indicate the row and column indices of the largest element in the two-dimensional array. Write a test program that prompts the user to enter a two-dimensional array and displays the location of the largest element in the array. Here is a sample run:

Enter the number of rows and columns of the array:  3 4
Enter the array:
23.5 35.2 2 10
4.5 3 45 3.5
35 44 5.5 9.6
The location of the largest element is at (1,2)

Reminders

  1. Include proper comments for all
  2. Use proper formatting, etc.
  3. Test with more than one set of data where it is appropriate
  4. Get the correct data outputted on the program before worrying about formatting

Submissions

  1. Create a software development report that includes the following for the program:
    • A problem summary (the big picture) for each program
    • A list of requirements for each program. (Things that this particular implementation of a solution must do)
    • A list of steps each of your programs do
    • A testing report for each program: What exact input you used and what output you got.
    • How long it took to write it, and how much time was on it each day!
    • Who you got help from (if you got help)
    • Changes (if any) you would make if you had more time and/or skill
    • At least two things you learned while writing the program(s)
  2. Create a zip folder with your software development report(s) and your java file(s) and submit that to canvas.
  3. Due date can be found on canvas