Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding and modifying an assignment (creation) class. (GUI, Java 1.8)  RSS feed

 
Marshall Mathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have been working on an assignment for a while now and it seems as if I was able to do most of the requirements (below), however, I was unable to finish part 7a and 7b. This is why I came here to hopefully get some help since I have no idea where I'm making a mistake which stops me from actually adding an assignment when the program is run, like it should.

I have added my whole program as a zip file so that you can have a look at it yourself as me posting code here, from multiple classes wouldn't make much sense, especially because I do not know where I'm making the mistake. Assignment class was done by me, and some parts of the Model class were done by me, the rest was provided. But if you need any more detail then hopefully the requirements below will help you understand.

Requirements:

You have been provided with a base project that enables you to enter student data
and the modules that they are enrolled in. It needs to be extended in order to
handle assignments and student submissions of those assignments. The project has
two packages (view and model). You must not modify any code in the view
package. You should be adding code to the StudentModel interface and Model
class in the model package and adding new classes to achieve the requirements
below. The system will provide messages if it cannot find what it expects in your
code.
You will be expected to
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.


Crossed out parts I'm not worrying about for now, as I believe that they can be dealt with later on. But like I said, most parts are done and 7 is mostly what I'm worried about. So if you have any more questions then by all means ask and I'll be happy to answer.
Thanks in advance.


My program (zipped): http://www.filedropper.com/assignment6v2
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know the drill by now. Show some effort and post the code you have.
 
Marshall Mathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You know the drill by now. Show some effort and post the code you have.


That's not a problem, the question is whether what I post is actually going to be of any value if you don't actually know how the program works.

Part from the Model class:


Assignment class:


Thanks.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to try to help you help us. Your posts should be focused on the problem you're having -- one problem, or a couple of very closely related problems.

Do:
* Tell us the exact problem you're having
* Post any errors you get
* Post the relevant code
* Post code that is well formatted and no lines longer than about 100 characters (80 is the standard)
* Post only enough (but enough!) code to illustrate the problem

Don't:
* Post pages of requirements
* Post links to downloads

The golden rule is: what would you need if someone else had this problem? How could you make it easier on them? We're all volunteers here.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't look like you've done this:

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.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
modifyAssignment has no return type and will not compile because of that. Always post code that can compile (unless the question is about code that won't compile). The method need to return the assignment it modified.
 
Marshall Mathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:modifyAssignment has no return type and will not compile because of that. Always post code that can compile (unless the question is about code that won't compile). The method need to return the assignment it modified.


I assume that return assignment (title, day, etc.) would be sufficient in that case?
And what about addAssignment since that's actually the most important part.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marshall Mathers wrote:
Knute Snortum wrote:modifyAssignment has no return type and will not compile because of that. Always post code that can compile (unless the question is about code that won't compile). The method need to return the assignment it modified.


I assume that return assignment (title, day, etc.) would be sufficient in that case?

Just return assignment; should work.
And what about addAssignment since that's actually the most important part.

You need to validate the parameters.
 
Marshall Mathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
Marshall Mathers wrote:
Knute Snortum wrote:modifyAssignment has no return type and will not compile because of that. Always post code that can compile (unless the question is about code that won't compile). The method need to return the assignment it modified.


I assume that return assignment (title, day, etc.) would be sufficient in that case?

Just return assignment; should work.
And what about addAssignment since that's actually the most important part.

You need to validate the parameters.


Unfortunately, return assignment doesn't. I tried that before and tried it once more, nothing. It says "Cannot return a value from a method with void result type.", so where do I change that?

And when it comes to the parameters, this is what i thought that I have to do but the thing is, I've got no idea how to do so. I tried various different ways and various different parameters as well as different calling methods to try to get the addAssignment to work. But still nothing.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, return assignment doesn't. I tried that before and tried it once more, nothing. It says "Cannot return a value from a method with void result type.", so where do I change that?

What does the error tell you? Change the result (return) type of the method from void to assignment.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when it comes to the parameters, this is what i thought that I have to do but the thing is, I've got no idea how to do so. I tried various different ways and various different parameters as well as different calling methods to try to get the addAssignment to work. But still nothing.

Post the code of your best guess and explain exactly what's not working. You can post just the modifyAssignment() method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!