Add 2 constructors to the Course class. One that takes no arguments and initializes the data to all 0’s and “” (empty strings). And one constructor that takes all 4 arguments, one argument for each property and then sets the properties to these arguments that are passed in. Lastly change the main to use these new Constructors. You will not need to call the set functions any more, but do not remove the set functions from your class.
Main Code --->
Course c1;
c1 = new Course(323, “Intro to Php”, “Intro to Php Programming”, 4);
c1.display();
Here my Code:
public class Course {
// ========================== Properties ===========================
private int courseid;
private String courseName;
private String description;
private int 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) { creditHours = ch; }
public int getCreditHours() { return creditHours;}
//Returning String
public String toString() {
return courseName + ":" + description;
}
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