Question
public class Course { private int CourseId; private String CourseName; private String Description; private int creditHours; public Course() { } public Course(int courseId, String courseName,
public class Course { private int CourseId; private String CourseName; private String Description; private int creditHours;
public Course() { }
public Course(int courseId, String courseName, String description, int creditHours) { CourseId = courseId; CourseName = courseName; Description = description; this.creditHours = creditHours; }
public int getCourseId() { return CourseId; }
public void setCourseId(int courseId) { CourseId = courseId; }
public String getCourseName() { return CourseName; }
public void setCourseName(String courseName) { CourseName = courseName; }
public String getDescription() { return Description; }
public void setDescription(String description) { Description = description; }
public int getCreditHours() { return creditHours; }
public void setCreditHours(int creditHours) { this.creditHours = creditHours; } public void display() { System.out.println("Course{" + "CourseId=" + CourseId + ", CourseName='" + CourseName + '\'' + ", Description='" + Description + '\'' + ", creditHours=" + creditHours + '}'); } }
Add 2 constructors to the Course class. One that takes no arguments and initializes the data to all 0s 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();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started