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

Accumulating Totals in Single-Level Control Break Programs Summary In this lab,

ID: 3597026 • Letter: A

Question

Accumulating Totals in Single-Level Control Break Programs

Summary

In this lab, you will use what you have learned about accumulating totals in a single-level control break program to complete a Java program. The program should produce a report for a supermarket manager to help her keep track of the hours worked by her part-time employees. The report should include the day of the week, the number of hours worked by each employee for each day, and the total hours worked by all employees each day.

Instructions

Study the prewritten code to understand what has already been done.

Write the control break code, including the code for the dayChange() method, in the main() method.

Execute this program using the following input values:

Monday – 6 hours (employee 1), 3 hours (employee 2), 4 hours (employee 3)

Tuesday – 4 hours (employee 1), 2 hours (employee 2)

Wednesday – 2 hours (employee 1), 4 hours (employee 2), 6 hours (employee 3)

Thursday – 4 hours (employee 1)

Friday – 3 hours (employee 1), 4 hours (employee 2), 3 hours (employee 3)

Saturday – 7 hours (employee 1), 7 hours (employee 2), 7 hours (employee 3)

Sunday – 0 hours

// SuperMarket.java - This program creates a report that lists weekly hours worked
// by employees of a supermarket. The report lists total hours for
// each day of one week.
// Input: Interactive
// Output: Report.

import java.util.Scanner;


public class SuperMarket
{
   public static void main(String args[])
   {
      // Declare variables.
      final String HEAD1 = "WEEKLY HOURS WORKED";
      final String DAY_FOOTER = "          Day Total "; // Leading spaces are intentional.
      final String SENTINEL = "done";     // Named constant for sentinel value.
      double hoursWorked = 0;             // Current record hours.
      String hoursWorkedString = "";      // String version of hours
      String dayOfWeek;       // Current record day of week.
      double hoursTotal = 0;           // Hours total for a day.
      String prevDay = "";             // Previous day of week.
      boolean done = false;            // loop control
      Scanner input = new Scanner(System.in);
      // Print two blank lines.
      System.out.println();
      System.out.println();
      // Print heading.
      System.out.println(HEAD1);
      // Print two blank lines.
      System.out.println();
      System.out.println();

      // Read first record
      System.out.println("Enter day of week or done to quit: ");
      dayOfWeek = input.nextLine();
      if(dayOfWeek.compareTo(SENTINEL) == 0)
         done = true;
      else
      {
         System.out.print("Enter hours worked: ");
         hoursWorkedString = input.nextLine();
         hoursWorked = Integer.parseInt(hoursWorkedString);
         prevDay = dayOfWeek;
      }
     
        
      while(done == false)
      {
         // Implement control break logic here
              // Include work done in the dayChange() method
      }
  
      System.out.println(DAY_FOOTER + hoursTotal);
              
      System.exit(0);

   } // End of main() method.
  
} // End of SuperMarket class.

Explanation / Answer

import javax.swing.*;

                public class HoursWorked

                {

                    public static void main(String args[])

                    {

                        final String HEAD1 = "WEEKLY HOURS WORKED";

                        final String FOOTER = "     Grand Total ";

                        final String SENTINEL = "done";   

                        double hoursWorked = 0;           

                        String hoursWorkedString = "";    

                        String dayOfWeek;          

                        double hoursTotal = 0;           

                        double grandTotal = 0;          

                        boolean notDone = true;        

                        System.out.println();

                        System.out.println();

                        System.out.println(HEAD1);

                        System.out.println();

                        System.out.println();

                        dayOfWeek = JOptionPane.showInputDialog("Enter day of week or done to quit: ");

                        if(dayOfWeek.compareTo(SENTINEL) == 0)

                        {

                            notDone = false;

                        }

                        else

                        {

                            hoursWorkedString = JOptionPane.showInputDialog("Enter hours worked: ");

                            hoursWorked = Integer.parseInt(hoursWorkedString);

                        }

                        while(notDone == true)

                        {

                            hoursTotal += hoursWorked;

                            System.out.println(dayOfWeek + " " + hoursWorked);

                            dayOfWeek = JOptionPane.showInputDialog("Enter day of week or done to quit: ");

                            if(dayOfWeek.compareTo(SENTINEL) == 0)

                            {

                                notDone = false;

                            }

                            else

                            {

                                hoursWorkedString = JOptionPane.showInputDialog("Enter hours worked: ");

                                hoursWorked = Integer.parseInt(hoursWorkedString);

                            }

                        }

                        System.out.println(FOOTER + hoursTotal);

                        System.exit(0);

                    }

                }

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