Here's what the question asks:
Build a class called Course.java. This class should have 4 properties: CourseId, CourseName, Description, and credit hours. Also add the appropriate set and get methods. Add a display() method to display these 4 properties out to the DOS window. Lastly add a main() method for testing. In the main() method instantiate a Course object, fill it with data using the set methods, then call the display method to display the data.
I just want to make sure is my code right and if there are mistake in my code.
public class Course {
// ========================== Properties ===========================
private int courseid;
private String courseName;
private String description;
private String creditHours;
// ========================== Behaviors ==========================
public void setCourseId(int c) { courseid = c; }
public int getCourseId() { return courseid;}
public void setCourseName(String cn) { courseName = cn; }
public String getCourseName() { return courseName;}
public void setDescription(String d) { description = d; }
public String getDescription() { return description;}
public void setCreditHours(int ch) { ch = 4; }
public int getCreditHours() { return ch;}
//Returning String
public String toString() {
return courseName + ":" + description + ":" + creditHours;
}
public void display() {
System.out.println("Course ID = " + getCourseId());
System.out.println("Course Name = " + getCourseName());
System.out.println("Description = " + getDescription());
System.out.println("Credit Hours = " + getCreditHours());
} //end display()
public static void main(String args []) {
Course c1;
c1 = new Course();
c1.setCourseId(109);
c1.setCourseName("Intro to Python");
c1.setDescription("This course intros the Python Prog Lang.");
c1.setCreditHours(4);
c1.display();
//Test out toString() method
System.out.println(c1);
} //end main
} //end class