Hi,
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??
public class Course { private String code; private String title; private int points; // complete the class constructor public Course(String aCode, String aTitle, int pts) { code = aCode; title = aTitle; points = pts; } //the toString method public String toString() { return (code + ", " + title + " (" + points + ") "); } //the equals method public boolean equals (Course c) { return code.equals(c.code); } //the validCode method //the validPoints method //the validTitle method //provided getters public String getCode() { return code; } public String getTitle() { return title; } public int getPoints() { return points; } }