i'm a complete newbie and i've been trying to do some course wotrk but i am completely lost with one of the activities i ahve been given. Here is the question;

In this scenario you are writing code related to a college record-keeping system that maintains information about a number of courses, each of which has a code (such as A 123), a title (such as ‘Advanced Florestry’) and a number of points gained (such as 60).
The college records certain details about its students, including their names and identifiers. Note that Instances of courses may have a number of students registered on them.
Develop the class called Course that describes a college course. The skeleton of the Courseclass has instance variables as follows:

code is a reference to the code of the course, a String;
title is a reference to the title of the course, a String;
points stores the number of points the course is worth, an int.

You are also provided with getter methods for these variables and a constructor to be completed in part (c). In this part, you should create toString and equals methods to override those inherited from the Object class. You are required to write the following methods:

the toString method should return a string containing the details of the course, including the course code, its title and the number of points gained in parentheses, for example A 123, Advanced Florestry(60);
the equals method should return true if the receiver object has the same course code as the object referenced by the argument to this method, otherwise it should return false. (We assume that course codes are unique.)

In this part, you should create an exception class called InvalidCoursein the same package as the Course class. We want this to be a checked exception, and it should have a single-argument constructor that takes a String message as an argument.
This class will be used to throw an exception in the event that an invalid course construction is attempted and is to be used in part (c) below.

In this part you should complete the Course class constructor, which receives a code, a title and a number of points gained, and sets the instance data of the constructed object to the received values.
The Course class will require the following helper methods to check the validity of the course data:

booleanvalidCode() receives a Stringcourse code as an argument and returns true if the course code begins with a letter and is followed by three digits, otherwise it returns false. You should use methods of the Character class to determine if characters are letters or digits.
booleanvalidPoints() receives an int value as an argument and returns true if the points value is a positive
booleanvalidTitle() receives a String and returns true if its value is not null; otherwise the method returns false.

You should ensure that the Course class constructor uses these helper methods to determine if the course data it receives is valid.

If the course data is valid, the constructor should complete normally, setting the instance data to the received values. If any of the arguments is not valid, the constructor should throw an InvalidCourse exception with an appropriate error message, which should include the faulty data value.

Now i'm just not getting anything to work here at all and i'm just getting in a mess. Here is what i have so far as i can't work out how to do the rest can anyone help me??

So, your exercise is split into 3 parts as I see it.
-Making a course class
-Making an exception for the course class
-Implementing the exception into the course class, using the 3 helper methods.

1.
You are almost done with the first point, but you need a little work on the overwritten equals method. You are currently only checking the code variable, where you should ideally check all 3 of the required variables.
Making a good equals method is not always as easy as it would first look. Hint: a good equals method should be: reflexive, symmetric and transitive.

2. Exceptions.
You are gonna need some reading here. You need to make clear to yourself, the difference between a checked and an unchecked exception. These two types exception make for different implementation, so understanding how they work is key here. The course literature should provide the information needed, if not, google will never let you down.

3.
Once you have a good understanding of the exception types, this part should not provide too much trouble.

Feel free to post further questions.

January 20th, 2010, 06:53 AM

PU_MPK_IN

Re: Desparate for Help

Thank you, i'll get reading and see what i can come up with!!

January 20th, 2010, 08:13 AM

Johannes

Re: Desparate for Help

If you run into concrete problems with implementation post it here and I will have a look.

January 23rd, 2010, 05:27 AM

Shambolic

Re: Desparate for Help

Although your code doesn't currently do what it needs to, it should compile, right?

You should be able to write the validation methods reasonably easily (the validCode method is the only one which might be a bit difficult), which will let you write your constructor properly, and then worry about writing the exception class.