Hello. I need help with an assignment. The assignment requires me to take user input from a multi dimensional array. That input which is of each employees hours for monday - friday is output in a table.
It works with an array in which I have hard coded the values. I need to know how to make it so that the values can be from user input.
Thank you
import java.util.Scanner; public class TimeBook { private int numberOfEmployees; private int[][] hours; //hours[i][j] has the hours for //employee j on day i. private int[] weekHours; //weekHours[i] has the week's //hours worked for employee i + 1. private int[] dayHours; //dayHours[i] has the total hours //worked by all employees on day i. private static final int NUMBER_OF_WORKDAYS = 5; // rows. private static final int MON = 0; private static final int TUE = 1; private static final int WED = 2; private static final int THU = 3; private static final int FRI = 4; private static final int NUMBER_OF_EMPLOYEES = 3; // textbook version has this in main as first line. public static void main(String[] args) { TimeBook book = new TimeBook(NUMBER_OF_EMPLOYEES); book.setHours(); book.update(); book.showTable(); } public TimeBook(int theNumberOfEmployees) { numberOfEmployees = theNumberOfEmployees; hours = new int[NUMBER_OF_WORKDAYS][numberOfEmployees]; weekHours = new int[numberOfEmployees]; dayHours = new int[NUMBER_OF_WORKDAYS]; } public void setHours() { hours[0][0] = 8; hours[0][1] = 0; hours[0][2] = 9; hours[1][0] = 8; hours[1][1] = 0; hours[1][2] = 9; hours[2][0] = 8; hours[2][1] = 8; hours[2][2] = 8; hours[3][0] = 8; hours[3][1] = 8; hours[3][2] = 4; hours[4][0] = 8; hours[4][1] = 8; hours[4][2] = 8; } public void update() { computeWeekHours(); computeDayHours(); } public void computeWeekHours() { for (int employeeNumber = 1; employeeNumber <=numberOfEmployees; employeeNumber++) {//Process one employee: int sum = 0; for (int day = MON; day <= FRI; day++){ sum = sum + hours[day][employeeNumber - 1]; //sum contains the sum of all the hours worked in //one //week by the employee with number employeeNumber. weekHours[employeeNumber - 1] = sum; } } } private void computeDayHours() { for (int day = MON; day <= FRI; day++) {//Process one day (for all employees): int sum = 0; for (int employeeNumber = 1;employeeNumber <= numberOfEmployees; employeeNumber++) { sum = sum + hours[day][employeeNumber - 1]; //sum contains the sum of all hours worked by all //employees on one day. dayHours[day] = sum; } } } public void showTable() { // HEADING BEGIN System.out.print("Employee \t"); for (int employeeNumber = 1;employeeNumber <= numberOfEmployees; // numberOfEmployees is 3. employeeNumber++) { System.out.print(employeeNumber + "\t"); } System.out.println("Total"); //added to display totals after final employee number. System.out.println(); //added to begin next line with day and hours beneath. // HEADING END // ROWS BEGIN for (int day = MON; day <= FRI; day++) { System.out.print(getDayName(day) + " "); for (int column = 0; column < hours[day].length; column++) { System.out.print(hours[day][column] + "\t"); //System.out.println(dayHours[day]); } System.out.println(dayHours[day]); //added to display sum of all employee hours for the day under 'Totals' col. System.out.println( ); //System.out.print("Total = "); // displays total of each employee at bottom line for week. } System.out.print("Total: \t\t"); for (int column = 0; column < numberOfEmployees; column++) { System.out.print(weekHours[column] + "\t"); } //Converts 0 to "Monday", 1 to "Tuesday", etc. // ROWS END } private String getDayName(int day) { String dayName = null; switch (day) { case MON: dayName = "Monday \t"; break; case TUE: dayName = "Tuesday \t"; break; case WED: dayName = "Wednesday \t"; break; case THU: dayName = "Thursday \t"; break; case FRI: dayName = "Friday \t\t"; break; default: System.out.println("Fatal Error."); System.exit(0);