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

public class timebook { private int numberOfEmployees: private int [] [] hours;

ID: 3658482 • Letter: P

Question

public class timebook

{

private int numberOfEmployees:

private int [] [] hours;

pirvate int [] weekHours;

private int [] dayHours;

private static final int NUMBER_OF_WORKDAYS = 5;

private static final int MON = 0;

private static final int TUE = 2;

private static final int WED = 3;

private static final int THU = 4;

private static final int FRI = 5;

public static void main(String[] args)

{

private static final int NUMBER_OF_EMPLOYEES = 3;

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][numberOfEmployes];

weekHours = new int [NumberOfEmployees];

dayHours = new int [NUMBER_OF_WORKDAYS];

}

public void setHours ()

{

hours [0][0] = 8; hours [0][1] = 0; hous [0][2] = 9;

hours [1][0] = 8; hours [1][1] = 0; hous [1][2] = 9;

hours [2][0] = 8; hours [2][1] = 8; hous [2][2] = 8;

hours [3][0] = 8; hours [3][1] = 8; hous [3][2] = 4;

hours [4][0] = 8; hours [4][1] = 8; hous [4][2] = 8;

}

public void update ()

{

computeWeekHours();

computeDayHours();

}

private void computeWeekHours()

{

for (employeeNumber = 1; employeeNumber <= numberOfEmployees; employeeNumber++)

{

int sum = 0;

for (int day = MON; day <= FRI; day++)

sum = sum + hours [day][employeeNumber - 1];

weekHours [employeeNumber - 1] = sum;

}

}

private void computeDayHours()

{

for (int day = MON; day <= FRI; day++)

{

int sum= 0;

for (int employeeNumber = 1;

employeeNumber <= numberOfEmployees; employeeNumber++)

sum = sum + hours [day][employeeNumber -1];

dayHours [day] = sum;

}

}

public void ShowTable()

{

System.out.print ("Employee");

for (int employeeNumber = 1; employeeNumber <=numberOfEmployees; employeeNumber++)

System.out.print(employeeNumber + " ");

System.out.println("Totals");

System.out.println();

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] + " ");

System.out.println (dayHours[day]);

}

System.out.println();

System.out.print ("Total = ");

for (int column = 0; column < numberOfEmployees; column++)

System.out.print(weekHours [column] + " ");

System.out.print();

}

private String getDayName (int day)

{

String dayName = null;

switch (day)

{

case MON:

dayName = "Monday";

break;

case TUE;

dayName = "Tuesday";

break;

case WED:

dayName = "Wednesday";

break;

case THU:

dayName = "Thursday";

break;

case FRI:

dayName = "Friday";

break;

default:

System.out.println("Fatal Error");

System.exit (0);

break;

}

return dayName;

}

}

need help with programming project ch 7, project 6

Explanation / Answer

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; 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; /** Reads hours worked for each employee on each day of the work week into the two-dimensional array hours. (The method for input is just a stub in this preliminary version.) Computes the total weekly hours for each employee and the total daily hours for all employees combined. */ public static void main(String[] args) { final int NUMBER_OF_EMPLOYEES = 3; 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( ) //This is a stub. { 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( ); } private void computeWeekHours( ) { for (int employeeNumber = 1; employeeNumber