Java Reference
In-Depth Information
The main characteristics of a course are the course name, course number, and
number of credit hours.
Some of the basic operations that need to be performed on an object of the course type are:
1. Set the course information.
2. Print the course information.
3. Show the credit hours.
4. Show the course number.
Next, we define the members of the
class
Course
.
Instance Variables:
private
String courseName;
//object to store the course name
private
String courseNo;
//object to store the course number
private int
courseCredits;
//variable to store the course
//credits
Constructors and Instance Methods:
public void
setCourseInfo(String cName, String cNo,
int
credits)
//Method to set the course information
//The course information is set according to the
//incoming parameters.
//Postcondition: courseName = cName; courseNo = cNo;
//
courseCredits = credits;
public void
setCourseName(String cName)
//Method to set the course Name
//Postcondition: courseName = cName;
public void
setCourseNumber(String cNo)
//Method to set the course Number
//Postcondition: courseNo = cNo;
public void
setCourseCredits(
int
credits)
//Method to set the course credits
//Postcondition: courseCredits = credits;
public
String toString()
//Method to return the course information as a string
//Postcondition: The course information is returned
//
as a string.
public
String getCourseName()
//Method to return the course name
//Postcondition: The value of courseName is returned.
public
String getCourseNumber()
//Method to return the course number
//Postcondition: The value of courseNo is returned.
Search WWH ::
Custom Search