***please help! READ the grading criteria***
HW5: Weekly Timesheet CSS 161 Fundamentals of Computing By: Hansel Ong Summary In
HW3, you created a program that allows the user to enter time worked on a week-by-week basis
Such a system calculated any hours worked over 40 hours a week as overtime. However, this
means that an employee could work 12 or 20 hours once a week, 4 hours the rest of the week,
and not be paid overtime at all. Let\'s fix this problem in this homework. For simplification, let\'s
limit the number of weeks the user can enter to two weeks maximum. Note also that any hours
worked in a day beyond 8 hours should be regarded as overtime hours. Estimated Work Needed
This assignment took me about 30-45 minutes to write (not including challenges, but including
testing, commenting, and cleanup) in less than 200 lines of code In other words, you should
expect to spend between 135 to 450 minutes working on this assignment. If you\'ve spent more
than 7.5 hours working on this assignment, then you are likely struggling with loops and/or
arrays and should re-read the lecture slides and attempt the exercises within seek help from your
fellow classmates, myself, your lab instructor, QSC tutor as well as online resources. Skills
Expected All the skills from previous Assignment(s) Arrays File I/O Assignment Description
Write a program that does the following Provide the following \"main menu\" to the user (Create
a method for each of the choices): o (1 point) Enter/Edit Timesheet o (1 point) Display
Timesheet o (1 point) Print Paystub (End Program) o (1 point) Keep presenting this menu to the
user until user asks to print a paystub For \"Enter/Edit Timesheet\" o (1 point) Ask the user
which week the user would like to edit (1 or 2) (1 point) Return to \"main menu\" if user chooses
anything other than 1 or 2 o (2 points) Display each day of the week (M, Tu, W and the number
of hours worked for each day (display 0 by default until user has entered a value) (2 point) Allow
the user to edit hours for specific days of the week (1 point) Return to \"main menu\" if user
enters an invalid day of the week or invalid hours of the day
Solution
// Paystub.java
import java.util.Scanner;
public class Paystub
{
static int insuranceDeduction = 25;
static int regularHours1 = 0;
static int overtimeHours1 = 0;
static int regularHours2 = 0;
static int overtimeHours2 = 0;
static int[] week1 = new int[7];
static int[] week2 = new int[7];
public static int mainMenu()
{
System.out.println(\"\ \ --------------Main Menu----------------\");
System.out.print(\"1. Enter/Edit Timesheet\ 2. Display Timesheet\ 3. Print Paystub (End
program)\ Please choose from the above options: \");
Scanner keyboard = new Scanner (System.in);
int choice = keyboard.nextInt();
return choice;
}
public static void inputHours()
{
Scanner keyboard = new Scanner (System.in);
System.out.print(\"Which week Would you like to enter/edit(1 or 2): \");
int week = keyboard.nextInt();
if(week == 1)
{
for.
1. ***please help! READ the grading criteria***
HW5: Weekly Timesheet CSS 161 Fundamentals of Computing By: Hansel Ong Summary In
HW3, you created a program that allows the user to enter time worked on a week-by-week basis
Such a system calculated any hours worked over 40 hours a week as overtime. However, this
means that an employee could work 12 or 20 hours once a week, 4 hours the rest of the week,
and not be paid overtime at all. Let's fix this problem in this homework. For simplification, let's
limit the number of weeks the user can enter to two weeks maximum. Note also that any hours
worked in a day beyond 8 hours should be regarded as overtime hours. Estimated Work Needed
This assignment took me about 30-45 minutes to write (not including challenges, but including
testing, commenting, and cleanup) in less than 200 lines of code In other words, you should
expect to spend between 135 to 450 minutes working on this assignment. If you've spent more
than 7.5 hours working on this assignment, then you are likely struggling with loops and/or
arrays and should re-read the lecture slides and attempt the exercises within seek help from your
fellow classmates, myself, your lab instructor, QSC tutor as well as online resources. Skills
Expected All the skills from previous Assignment(s) Arrays File I/O Assignment Description
Write a program that does the following Provide the following "main menu" to the user (Create
a method for each of the choices): o (1 point) Enter/Edit Timesheet o (1 point) Display
Timesheet o (1 point) Print Paystub (End Program) o (1 point) Keep presenting this menu to the
user until user asks to print a paystub For "Enter/Edit Timesheet" o (1 point) Ask the user
which week the user would like to edit (1 or 2) (1 point) Return to "main menu" if user chooses
anything other than 1 or 2 o (2 points) Display each day of the week (M, Tu, W and the number
of hours worked for each day (display 0 by default until user has entered a value) (2 point) Allow
the user to edit hours for specific days of the week (1 point) Return to "main menu" if user
enters an invalid day of the week or invalid hours of the day
Solution
// Paystub.java
import java.util.Scanner;
public class Paystub
{
static int insuranceDeduction = 25;
2. static int regularHours1 = 0;
static int overtimeHours1 = 0;
static int regularHours2 = 0;
static int overtimeHours2 = 0;
static int[] week1 = new int[7];
static int[] week2 = new int[7];
public static int mainMenu()
{
System.out.println(" --------------Main Menu----------------");
System.out.print("1. Enter/Edit Timesheet 2. Display Timesheet 3. Print Paystub (End
program) Please choose from the above options: ");
Scanner keyboard = new Scanner (System.in);
int choice = keyboard.nextInt();
return choice;
}
public static void inputHours()
{
Scanner keyboard = new Scanner (System.in);
System.out.print("Which week Would you like to enter/edit(1 or 2): ");
int week = keyboard.nextInt();
if(week == 1)
{
for (int i = 0; i < 7 ; i++ )
{
System.out.println("Day " + (i+1) + ": " + week1[i] + " hours worked");
}
System.out.print("Which day Would you like to edit(1-7): ");
int day = keyboard.nextInt();
System.out.print("How many hours did you work on day " + day + "? " );
week1[day] = keyboard.nextInt();
if(week1[day] > 8)
{
regularHours1 = regularHours1 + 8;
overtimeHours1 = overtimeHours1 + (week1[day]-8);
}
3. else
{
regularHours1 = regularHours1 + week1[day];
}
}
else if(week == 2)
{
for (int i = 0; i < 7 ; i++ )
{
System.out.println("Day " + (i+1) + ": " + week2[i] + " hours worked");
}
System.out.print("Which day Would you like to edit(1-7): ");
int day = keyboard.nextInt();
System.out.print("How many hours did you work on day " + day + "? " );
week2[day] = keyboard.nextInt();
if(week2[day] > 8)
{
regularHours2 = regularHours2 + 8;
overtimeHours2 = overtimeHours2 + (week2[day]-8);
}
else
{
regularHours2 = regularHours2 + week2[day];
}
}
}
public static void display()
{
System.out.println(" -------------Week 1----------------");
System.out.println("Regular Hours: " + (regularHours1) + " Overtime hours: " +
(overtimeHours1) + " ");
System.out.println(" -------------Week 2----------------");
System.out.println("Regular Hours: " + (regularHours2) + " Overtime hours: " +
(overtimeHours2));
}
5. }
while(true)
{
int choice = mainMenu();
if(choice == 1)
{
inputHours();
}
else if(choice == 2)
{
display();
}
else if(choice == 3)
{
paystub();
break;
}
else
System.out.println("Invalid Input");
}
System.out.println(" ************************************");
System.out.println("Thanks for using out system!");
System.out.println("************************************");
}
}
/*
output:
--------------Main Menu----------------
1. Enter/Edit Timesheet
2. Display Timesheet
3. Print Paystub (End program)
Please choose from the above options: 1
Which week Would you like to enter/edit(1 or 2): 1
6. Day 1: 0 hours worked
Day 2: 0 hours worked
Day 3: 0 hours worked
Day 4: 0 hours worked
Day 5: 0 hours worked
Day 6: 0 hours worked
Day 7: 0 hours worked
Which day Would you like to edit(1-7): 2
How many hours did you work on day 2? 7
--------------Main Menu----------------
1. Enter/Edit Timesheet
2. Display Timesheet
3. Print Paystub (End program)
Please choose from the above options: 1
Which week Would you like to enter/edit(1 or 2): 1
Day 1: 0 hours worked
Day 2: 0 hours worked
Day 3: 7 hours worked
Day 4: 0 hours worked
Day 5: 0 hours worked
Day 6: 0 hours worked
Day 7: 0 hours worked
Which day Would you like to edit(1-7): 4
How many hours did you work on day 4? 12
--------------Main Menu----------------
1. Enter/Edit Timesheet
2. Display Timesheet
3. Print Paystub (End program)
Please choose from the above options: 1
Which week Would you like to enter/edit(1 or 2): 2
Day 1: 0 hours worked
Day 2: 0 hours worked
Day 3: 0 hours worked
Day 4: 0 hours worked
7. Day 5: 0 hours worked
Day 6: 0 hours worked
Day 7: 0 hours worked
Which day Would you like to edit(1-7): 3
How many hours did you work on day 3? 10
--------------Main Menu----------------
1. Enter/Edit Timesheet
2. Display Timesheet
3. Print Paystub (End program)
Please choose from the above options: 2
-------------Week 1----------------
Regular Hours: 15
Overtime hours: 4
-------------Week 2----------------
Regular Hours: 8
Overtime hours: 2
--------------Main Menu----------------
1. Enter/Edit Timesheet
2. Display Timesheet
3. Print Paystub (End program)
Please choose from the above options: 3
-------------Week 1----------------
Regular Hours: 15
Overtime hours: 4
-------------Week 2----------------
Regular Hours: 8
Overtime hours: 2
---------Gross Income---------------
Regular Pay: 23 hours * $15.0 = $345.0
Overtime Pay: 6 hours * $15.0* 1.5 = $135.0
Gross Income: $480.0
---------Deductions---------------
8. Medical and Dental Insurance: $50
Federal Taxes: $129.0
---------takehome Income---------------
Takehome Income: $345.0+ $135.0- $50- $129.0 = $301.0
************************************
Thanks for using out system!
************************************
*/