Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume you work in a tutoring center, which operates Mon-Wed. The center keeps t

ID: 3621822 • Letter: A

Question

Assume you work in a tutoring center, which operates Mon-Wed. The center keeps track of how many students come to the center and which tutors they see, similar to the table below:

 tutor

Mon

Tue

Wed

Amy

25

3

0

John

14

5

12

Nick

33

22

10

Maria

0

20

5

 

Write a Java program that does the following:

(1) The program shall read the number of tutors from the command line into variable numOfTutors. E.g.:

c:> java uin5679hw4 4 executes the program “uin5679hw4” with “4” as the parameter for the number of tutors.

 

(2) The program shall read the data as integers from a file named “tutors.txt” into a two-dimensional array named tutorData[numOfTutors][3]. (Please note that in the example above, the numbers in bold are in the file and then stored in the array and not the headings of rows/columns). The file has numOfTutors total lines, each line contains 3 integers (number of students per day for a tutor), separated by spaces.

 25 3 0
14 5 12
33 22 10
0 20 5

(3) The program shall print the following output (underlined = values computed from program):

“Total number of students using the center:

M: value, Tu: value, W: value. Total: value . (sum of students for each day, sum of all day sums)

Tutor1: value, Tutor2: value, …. Total: value . (sum of students for each tutor, sum of all tutor sums)

Max total students per day: value . (max of all day sums)

Max students per tutor: value . (max of all tutor sums)

Minimum number of students in all slots: value.” (min of all elements of array)

 

(4) The program shall use int[] arraysto store results for above computations: sumPerDay[3], sumPerTutor[numOfTutors].

 

(5) The program shall use the following methods:

readData() to read the data from the file in (2). The method takes an 2-D int[][] array as parameter (the tutorData) and returns nothing.

max1dArray() to calculate the maximum value of a 1-D array, e.g. sumPerDay[]. This method shall take an int[] array as parameter, and return an int as the result.

min1dArray() to calculate the min value of a 1-D array, e.g. a row of tutorData. This method shall take an int[] array as parameter, and return an int as the result.

Note: please note that the displayed max is of a sum, either per row (tutor) or per column (day), while the displayed min is calculated for all the individual array elements.

 tutor

Mon

Tue

Wed

Amy

25

3

0

John

14

5

12

Nick

33

22

10

Maria

0

20

5

Explanation / Answer

The code is not formatting correctly here, so here is a link to the same code that is actually readable:

http://snipt.org/nwpm/

import java.util.*; import java.io.*; public class TutoringCenter{ private static Scanner s; private static int[][] tutorData; public static void main(String[] args){ int numOfTutors = Integer.valueOf(args[0]); tutorData = new int[numOfTutors][3]; readData(tutorData); //Do calculations for output int[] sumPerDay = new int[3]; int[] sumPerTutor = new int[numOfTutors]; //Find max students per day int sum1 = 0; for(int i = 0; i < 3; i++){ for(int j = 0; j < numOfTutors; j++){ sum1 += tutorData[j][i]; } sumPerDay[i] = sum1; sum1 = 0; } int maxStudentsPerDay = max1dArray(sumPerDay); //Find max students per tutor for(int i = 0; i < numOfTutors; i++){ for(int j = 0; j < 3; j++){ sum1 += tutorData[i][j]; } sumPerTutor[i] = sum1; sum1 = 0; } int maxStudentsPerTutor = max1dArray(sumPerTutor); //Output time System.out.println("Total number of students using the center:"); // Output first line System.out.printf("M: %d, Tu: %d, W: %d. Total: %d.%n",sumPerDay[0], sumPerDay[1],sumPerDay[2], sumPerDay[0]+sumPerDay[1]+sumPerDay[2]); //Output second line for(int i = 0; i < numOfTutors; i++){ if(i == numOfTutors -1) {System.out.printf("Tutor%d: %d. ",i+1,sumPerTutor[i]);} else System.out.printf("Tutor%d: %d, ",i+1,sumPerTutor[i]); } int count = 0; while(count < numOfTutors){ sum1 += sumPerTutor[count]; count++; } System.out.printf("Total: %d.%n",sum1); //Output third line System.out.printf("Max total students per day: %d.%n",maxStudentsPerDay); //Output fourth line System.out.printf("Max students per tutor: %d.%n",maxStudentsPerTutor); // Output fifth line. I was not certain exactly what you wanted // outputted in the fifth line, so I wrote it so that it // outputs the lowest int in the two-dimensional array. int min = tutorData[0][0]; int[] a = new int[numOfTutors]; for(int i = 0; i < 3; i++){ for(int j = 0; j < numOfTutors; j++){ a[j] = tutorData[j][i]; } int k = min1dArray(a); if(k < min){min = k;} } System.out.printf("Minimum number of students in all slots: %d.%n",min); } // end main private static void readData(int[][] a){ try{ s = new Scanner(new File("tutors.txt")); } catch(Exception e){} Scanner l; int tutor = 0, day = 0; while(s.hasNextLine()){ l = new Scanner(s.nextLine()); while(l.hasNext()){ a[tutor][day] = Integer.valueOf(l.next()); day++; } tutor++; day = 0; } } // end readData public static int max1dArray(int[] a){ int ans = a[0]; for(int i = 1; i < a.length; i++){ if(a[i] > ans) ans = a[i]; } return ans; } public static int min1dArray(int[] a){ int ans = a[0]; for(int i = 1; i < a.length; i++){ if(a[i] < ans) ans = a[i]; } return ans; } } // end TutoringCenter

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote