UML, References
UML, References
Scenario
The Fynbos Flower company is flexible on the hours that employees work, and as a consequence,
timekeeping is an important administrative practice. The company records the dates and times of
shifts (for want of a better word). Employees sign-in when they arrive and sign-out when they
leave. The start of a shift and the end of a shift always fall within the same week.
Though, currently, none of the employees bear the same name, the company assigns each a
unique ID number that may be used to disambiguate.
The concept of a "week" bears elaboration. A business week starts on a Monday and ends on a
Sunday. The weeks are numbered. The first week of the year is the one that contains the first
Thursday of the year.
In the appendix you will find a set of specifications for an Employee class and classes that it depends
on: Shift, Week, CalendarTime, Date, Time, Duration and TimeUnit.
Exercise one concerns constructing a UML class diagram for the classes, showing attributes,
constructors, methods, and associations.
On the Vula assignment page you will find a ZIP file containing Java code for Week, CalendarTime,
Date, Time, Duration and TimeUnit.
Continued
2
System.out.println(shift.start());
System.out.println(shift.finish());
System.out.println(shift.inWeek(new Week("35/2019")));
System.out.println(shift.inWeek(new Week("36/2019")));
System.out.println(shift.inWeek(new Week("37/2019")));
System.out.println(Duration.format(shift.length(), "minute"));
//
Continued
3
true
false
1/9/2019%06:00:00 - 1/9/2019%18:00:00
12 hours
NOTE: Each employee has a collection of shifts. You will need some type of collection object. An
ArrayList is recommended.
Continued
4
CalendarTime cTimeOne =
new CalendarTime(new Date("6/9/2023"), new Time("12:10"));
CalendarTime cTimeTwo =
new CalendarTime(new Date("6/9/2023"), new Time("20:18"));
CalendarTime cTimeThree =
new CalendarTime(new Date("6/9/2023"), new Time("20:18"));
CalendarTime cTimeFour =
new CalendarTime(new Date("7/9/2023"), new Time("2:00"));
System.out.println();
System.out.println(eOne.worked(shiftA));
System.out.println(eOne.worked(shiftB));
It assumes an Employee class method called ‘worked()’ that accepts a Shift object as a parameter
and compares it with each in the Employee object’s Shift collection.
Extend your Employee class with an implementation of ‘worked’, and your Shift class with the
method(s) required to support it.
HINT: Study section 5.2 of the course text for the modifications you need to make to your Shift class.
Continued
5
yourstudentnumber.zip
Appendices
Class Employee
An object of this class represents an Employee from the perspective of time keeping. It records the
employee name and ID, and logs sign-ins and sign-outs.
Constructors
public Employee(String name, String uid)
// Create an Employee representing the employee with given name and UID.
Methods
public String name()
// Obtain this employee’s name.
Continued
6
Class Shift
An object of this class represents a work shift. A shift begins on a given date at a given time and ends on a
given date at a given time.
Constructors
public Shift(CalendarTime start, CalendarTime finish)
// Create a Shift object representing a shift worked between the given date times.
Methods
public CalendarTime start()
// Obtain the start date and time for this shift.
Class Week
An object of this class represents a business week. A business week starts on a Monday and ends on a
Sunday. The business weeks of a year are numbered. The first week of the year is the one that contains the
first Thursday of the year.
Constructors
public Week(int n, int y)
// Create a Week object that represents business week number n in year y.
Methods
public boolean includes(Date d)
// Determine whether this business week includes the given date d.
Continued
7
Class CalendarTime
An object of this class represents a calendar time i.e. a date and time.
Instance variables
private Date date;
private Time time;
Constructors
public CalendarTime(Date d, Time t)
// Create a CalendarTime object that represents the given date and time.
Methods
public int compareTo(CalendarTime other)
// Returns a value of -1, 0, or 1 depending on whether this calendar time precedes, is equivalent
// to, or follows the given calendar time, other.
Class Time
A Time object represents a twenty-four-hour clock reading composed of hours, minutes and seconds.
Constructors
public Time(int h, int m)
// Create a Time representing the hth hour and mth minute of the day.
Methods
public Duration subtract(Time other)
// Set the first, middle and last names of this Student object.
Continued
8
Class Date
A Date object represents Gregorian calendar date.
Constructors
public Date(int d, int m, int y)
// Create a Date representing day d, month m, and year y.
Methods
public int compareTo(Date other)
// Compare this Date to other date, returning a -ve number if this precedes other, a zero if they
// are coincident, and a positive number if other precedes this.
Class Duration
A Duration object represents a length of time (with millisecond accuracy).
Constructors
public Duration(String timeUnit, long quantity)
// Create a Duration object that represents the given quantity of the given time unit.
// Permissible time units are: “millisecond”, “second”, “minute”, “hour”, “day” ,”week”.
Methods
public int compareTo(Duration other)
// Returns a negative, zero, or positive value, depending on whether this duration is smaller, equal
// to, or greater than the other duration.
Continued
9
Class TimeUnit
A TimeUnit is a (sub) type of duration that has a name, such as ‘hour’, ‘minute’, ‘week.
Fields (Constants)
public final static TimeUnit MILLISECOND;
public final static TimeUnit SECOND;
public final static TimeUnit MINUTE;
public final static TimeUnit HOUR;
public final static TimeUnit DAY;
public final static TimeUnit WEEK;
Methods
public String getName()
// Obtain this time unit’s name..
End