Update on what I've managed to come up with so far. I think that I more or less know how the date is supposed to work but now I encountered another issue and I am not sure how to solve it so hopefully after posting the code here, I'll be able to get an answer to my problem. In short, I am not sure about a few requirements that I need to implement for my solution to the assignment to work. That's why I'll also post the full requirements below.
Requirements:
1. Create an Assignment class that can be used to create assignment objects. The
class should have fields for a reference to the module associated with the
assignment, the title of the assignment, the date when the assignment is due,
the time when the assignment is due, and the percentage of the module grade
that the assignment counts for.
2. The Assignment class should have an appropriate constructor method that
enables all the fields to be set. All fields should also have getters and setter
methods for each of the fields.
3. There should be a factory method in the Assignment class that verifies the data
entered and only creates an assignment object if the supplied data is valid.
4. The class should have an equals(Object o) method that will return true if the
two assignment objects are for the same module and have the same title.
5. The class should have a toString() method that will return a String of the form
“<module code>: <assignment title> due on dd/mm/yyyy at hh:mm” where
<module code> is the module code for the associated module, <assignment
title> is the tile od the assignment, dd/mm/yyyy is the date on which the
assignment is due, and hh:mm is the time when the assignment is due.
6. You should also write a corresponding test class for the Assignment class to
verify the operation of all the methods in the Assignment class.
7. In order for the system to work, the Model class needs a number of methods
added. The view code checks whether these methods exist and reports an error
message if the required method does not exist. These methods are:
a. addAssignment: This method should create an Assignment object
using the currently selected Module object and the parameter data
passed to the method. It should return a reference to the created
Assignment object. The parameters for this method are a String title,
an integer day number, an integer month number, and integer year
number, an integer hour number, and an integer percentage. These
parameter values should be validated according to the rules below and
the object should only be created if the parameters are valid. NOTE:
The view code will use the returned reference to output a message to
say that the object was successfully created.
b. modifyAssignment: This method should modify the current
assignment object if one has been created. If there is no current
assignment object, it should do nothing. This method receives the same
parameters as the addAssignment method and it should validate the
parameter data in the same way as the addAssignment method. This
method should return a reference to the modified object.
c. getCurrentAssignment: This method should return a reference to the
current assignment. There are no parameters for this method. If there is
no current assignment, it should return null.
d. clearAssignment: This method should clear the currently selected
assignment. There are no parameters for this method and no return
value. This will have the effect of clearing the input fields on the
Assignment data entry panel. The following get… methods need to be
implemented to see this effect.
e. getAssignmentTitle: This method should return the title of the current
assignment. There are no parameters for this method. If there is no
current assignment, it should return null.
f. getAssignmentDay: This method should return the day that the current
assignment is due. There are no parameters for this method. If there is
no current assignment, it should return 0.
g. getAssignmentMonth: This method should return the month that the
current assignment is due. There are no parameters for this method. If
there is no current assignment, it should return 0.
h. getAssignmentYear: This method should return the year that the
current assignment is due. There are no parameters for this method. If
there is no current assignment, it should return 0.
i. getAssignmentHour: This method should return the hour that the
current assignment is due. There are no parameters for this method. If
there is no current assignment, it should return 0.
j. getAssignmentMinute: This method should return the minute that the
current assignment is due. There are no parameters for this method. If
there is no current assignment, it should return 0.
k. getAssignmentPercent: This method should return the percentage
assigned to the current assignment. There are no parameters for this
method. If there is no current assignment, it should return 0.
8. Write a test class to verify that the methods added to the Model class work as
expected. You may add additional methods to the model class to support these
methods and your testing.
9. The following data validation rules should be applied:
a. None of the string fields should be blank.
b. Any year fields must be a four digit number (i.e. greater than 999) and
less than or equal to 2016.
c. Any month field should be a number between 1 and 12 inclusive.
d. Any day field should be a number between 1 and 31 inclusive where
the month is January (1), March (3), May (5), July (7), August (8),
October (10), and December (12), between 1 and 30 inclusive where
the month is April (4), June (6), September (9), and November (11),
and between 1 and 28 for February (2). We are ignoring leap years for
this exercise.
e. The hour should be a number between 0 and 23 inclusive.
f. The minute should be a value between 0 and 59 inclusive.
g. The percentage should be a value between 1 and 100 inclusive. In the
next assignment, you will be expected to verify that the total of the
percentages for assignments assigned to a module do not exceed 100.
h. If the data is not valid then you should ensure that you add an error
message saying why the action was not completed. You should also
ensure that the error messages are cleared when the next action is
performed.
i. These validation rules should be verified by your test methods.
(Tests are crossed out as they can be dealt with later on.)
Code:
Model class
(Everything to do with assignment was done by me and the rest was already provided):
Assignment class
(done by me):
What I'm asking from you is to (if possible) tell me where I'm going wrong and why when I start up the program, I can't add a new assignment, etc.
If you have any further questions, would like me to clear something up or would like me to provide you with the full file then please ask. Thanks in advance for all the help!