0% found this document useful (0 votes)
3 views9 pages

UML, References

The document outlines the instructions for CSC1016S Assignment 7, which involves UML modeling and Java class implementation for a timekeeping system at the Fynbos Flower company. It includes exercises for creating UML diagrams for classes like Employee and Shift, and implementing their functionalities in Java. The assignment also emphasizes the importance of timekeeping and provides specific requirements for class methods and behaviors.

Uploaded by

fidaxay739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

UML, References

The document outlines the instructions for CSC1016S Assignment 7, which involves UML modeling and Java class implementation for a timekeeping system at the Fynbos Flower company. It includes exercises for creating UML diagrams for classes like Employee and Shift, and implementing their functionalities in Java. The assignment also emphasizes the importance of timekeeping and provides specific requirements for class methods and behaviors.

Uploaded by

fidaxay739
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Version: 06/09/2023 12:18

CSC1016S Assignment 7: UML Modelling,


Reference Types
Assignment Instructions
This assignment concerns the development of UML models, and the construction of classes in Java
using object composition i.e., write class declarations that define types of object that contain and
manipulate other objects.

This assignment is based on the following scenario:

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.

This information supports a range of enquiries


o whether an employee is present,
o whether an employee was present on a given day,
o the details of the shift worked on a given day,
o the total hours worked during a given week.
o the shifts worked during a given 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.

Exercise two concerns implementing the Shift class.

Exercise three concerns implementing the Employee class.

Continued
2

Exercise One [30 marks]


Drawing on the described scenario, your task is to study the class specifications in the appendix, and
the supplied code, and develop an equivalent UML class diagram.

• Your diagram should depict all the classes.


• For each class you should give public attributes and operations, including those that are
static.
• Your diagram should show relationships. Specifically, instances of generalisation,
association, and aggregation.
• Associations and aggregations should be annotated with multiplicity.

Exercise Two [25 marks]


Implement the Shift class as specified in the appendix. To evaluate your work, you should use the
interactive features of JGrasp and/or construct test code.

The following code fragment demonstrates class behaviour:


//
CalendarTime start = new CalendarTime("2/9/2019%22:00");
CalendarTime finish = new CalendarTime("3/9/2019%06:00");
Shift shift = new Shift(start, finish);
System.out.println(shift);

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"));
//

The output will be:


2/9/2019%22:00:00 - 3/9/2019%06:00:00
2/9/2019%22:00:00
3/9/2019%06:00:00
false
true
false
8 hours

Continued
3

Exercise Three [35 marks]


Implement the Employee class as specified in the appendix. To evaluate your work, you should use
the interactive features of JGrasp and/or construct test code.

The following (extensive) code fragment demonstrates class behaviour:


//
Employee employee = new Employee("Sivuyile Ngesi", "01010125");
System.out.println(employee.name());
System.out.println(employee.UID());
System.out.println(employee.present());
//
System.out.println();
employee.signIn(new Date(1, 9, 2019), new Time(6,00));
System.out.println(employee.present());
employee.signOut(new Date(1, 9, 2019), new Time(18,00));
System.out.println(employee.present());
//
employee.signIn(new Date(2, 9, 2019), new Time(16, 30));
employee.signOut(new Date(3, 9, 2019), new Time(2, 30));
//
employee.signIn(new Date(3, 9, 2019), new Time(18,00));
employee.signOut(new Date(4, 9, 2019), new Time(4,00));
//
System.out.println();
List<Shift> shifts = employee.get(new Week(35, 2019));
for(Shift shift : shifts) { System.out.println(shift); }
//
System.out.println();
System.out.println(Duration.format(employee.hours(new Week(35,
2019)), "minute"));

The code produces the following output:


Sivuyile Ngesi
01010125
false

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.

Question 4 [10 marks] (Manually Marked)


This question concerns class types as ‘reference’ types and the issue of ‘equivalence’. Consider the
following code fragment:

Continued
4

Employee eOne = new Employee("Loyiso Gola", "392621");

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"));

Shift shiftA = new Shift(cTimeOne, cTimeTwo);


Shift shiftB = new Shift(cTimeThree, cTimeFour);
Shift shiftC = new Shift(cTimeTwo, cTimeFour);

eOne.signIn(new Date("6/9/2023"), new Time("12:10"));


eOne.signOut(new Date("6/9/2023"), new Time("20:18"));

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.

We require the fragment to produce the following output:


true
false

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.

Note that the following code fragment:


System.out.println(cTimeOne.equals(cTimeTwo));
System.out.println(cTimeOne==cTimeTwo);
System.out.println(cTimeTwo.equals(cTimeTwo));
System.out.println(cTimeTwo==cTimeTwo);
System.out.println(cTimeTwo.equals(cTimeThree));

Produces the output:


false
false
true
true
true

Continued
5

Marking and Submission


Submit your UML class diagram and Shift.java and Employee.java classes all contained
within a single .ZIP folder to the automatic marker. The zipped folder should have the following
naming convention:

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.

public void UID()


// Obtain this Employee’s ID.

public void signIn(Date d, Time t)


// Record that this employee has begun a shift on the given date and at the given time.

public void signOut(Date d, Time t)


// Record that this employee has completed a shift on the given date and at the given time.

public boolean present()


// Determine whether this employee is present i.e. has signed-in and not yet signed-out.

public List<Shift> get(Week w)


// Obtain a list of the shifts worked by this employee during the given week.

public Duration hours(Week w)


// Returns the total time (hours and minutes) worked during the given week.

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.

public CalendarTime finish()


// Obtain the end date and time for this shift.

public boolean inWeek(Week w)


// Determine whether this shift occurred within the given week.

public Duration length()


// Obtain the length of this shift.

public String toString()


// Obtain a string representation of this shift of the form "<date>%:<time>-<date>%:<time>".

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.

public Week(String string)


// Create a Week object from a string of the form "<number>/<year>" where "<number>" is up to
two digits long, and "<year>" is a 4-digit number.

Methods
public boolean includes(Date d)
// Determine whether this business week includes the given date d.

public boolean equals(Object o)


// Determine whether object o is a Week that represents the same week as this Week.

public String toString()


// Obtain a String representation of this Week of the form "<number>/<year>".

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.

public Date date()


// Returns the date component.

public Time time()


// Returns the time component.

public Duration subtract(CalendarTime other)


// Subtract the given CalendarTime from this CalendarTime.

public boolean equals(Object o)


// Determine whether object o is a Date that represents the same date as this Date.

public String toString()


// Obtain a string representation of this CalendarTime in the form "<date>%<time>".

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.

public Time(String reading)


// Create a Time object from a string representation of a twenty-four-hour clock reading
// of the form ‘hh:mm[:ss]’ e.g. “03:25”, “17:55:05”.

Methods
public Duration subtract(Time other)
// Set the first, middle and last names of this Student object.

public boolean equals(Object o)


// Determine whether object o is a Time that represents the same time as this Time.

public String toString()


// Obtain a String representation of this Time object in the form ”HH:MM:SS”.

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.

public Date(String string)


// Create a Date from a string of the form "[d]d/[m]m/yyyy".

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.

public Duration subtract(Date other)


// Obtain the time from the other date to this date.

public boolean equals(Object o)


// Determine whether object o is a Date that represents the same date as this Date.

public String toString()


// Obtain a String representation of this date in the form [d]d/[m]m/yyyy.

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.

public boolean equals(Object o)


// Determine whether object o is equivalent to this object i.e. if it is a Duration and of the same
// value as this Duration.

public static String format(final Duration duration, final String smallestUnit)


// Obtain a formatted string that expresses the given duration as a series of no-zero quantities of
// the given time units.
// For example: Given Duration d=new Duration("second", 88893);, the expression
// Duration(d, "second") returns the string "1 day 41 minutes 33 seconds", while
// Duration(d, "minute") returns the string "1 day 41 minutes".

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..

public static TimeUnit[] values()


// Obtain an array of all the defined time units.

public static TimeUnit parse(String string)


// Obtain the TimeUnit with the given name. Returns null if the string does not match any of
// the defined units.

End

You might also like