//An instance of this class represents a 5-day Time-Card public class TimeCard { //A class to represent days of the work week public enum WorkDay { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY; public String brief() { return this == THURSDAY ? "R" : this.toString().substring(0,1); } } //Instance Variable: Hours worked on each work day private double[] hours = new double[WorkDay.values().length]; //Constructor: Creates an "unmarked" TimeCard public TimeCard() { this.reset(); } //Accessor: returns the hours from this TimeCard public double[] getHours() { double[] hours = new double[this.hours.length]; for (int day = 0; day < this.hours.length; day++) hours[day] = this.hours[day]; return hours; } //Mutator: Update this TimeCard entry for one work day public void addHours(WorkDay day, double hours) { this.hours[day.ordinal()] += hours; } //Mutator: reset all hours of this TimeCard to 0.0 public void reset() { for (int day = 0; day < this.hours.length; day++) this.hours[day] = 0.0; } //Override: Returns an image of the state of this TimeCard public String toString() { String image = ""; for (WorkDay day : WorkDay.values()) image += day.brief() + ":" + this.hours[day.ordinal()] + " "; return image.trim(); //return super.toString(); } //Override public boolean equals(Object other) { if (other == null || this.getClass() != other.getClass()) return false; TimeCard that = (TimeCard)other; for (int day = 0; day < this.hours.length; day++) if (this.hours[day] != that.hours[day]) return false; return true; } }