CPE 103 Lab Activity

Exploring Enums

Prerequisite: Read this short tutorial on Java Enums.

These references may also help: Enum javadocs and Java Specification for Enums and Arrays.

Part 1

Create an implementation for an enum DayOfWeek with the following values and associated abbreviation:


Value
Abbreviation
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
  M
  T
  W
  R
  F
  S
  Y

You must implement the methods defined in this API.
Do not use a switch statement (or if-chain) to implement any of your methods. For an extra challenge, create a solution where no method contains a loop.
Note the tutorial uses the static values() method to return an array containing the constants of an enum type, in the order they're declared.

Here is a driver to exercise your enum. (The driver belongs in a separate source file.)  The output from the driver should match these results.

Write your own JUnit tests to exercise your enum.

Challenge: Make only one change to the source so that SUNDAY is the first value.  Run the driver again, it should produce the same results.


Part 2

Create a program that uses the DayOfWeek enum you created to process a set of time cards. A time card contains an employee id number, a day of the week, and an integer hours worked. The program should read from data from standard input and send the results to standard output.
Each line of input contains three fields, separated by one or more blanks. There may be any number of input lines, terminated by EOF. The program should compute the total hours worked on weekdays ("regular hours") and the the total hours worked on weekends ("overtime hours").

The application class containing the main method should be named OvertimeApp
Example unix command:
java OvertimeApp < timecards   will produce this output.


Submit your completed source code files (including unit tests) to PolyLearn.

Submit your work as described in the syllabus.