Using the Course class as defined in Coursejava construct an
Solution
Please follow the code and comments for description :
CODE :
a) Course.java :
public class Course { // parent class
private String _department; // instance variables
 private int _number;
 private int _hours;
public Course(int h, String d, int n) { // constructor
 this._department = d;
 this._number = n;
 this._hours = h;
 }
public String getDepartment() { // getter methods
 return _department;
 }
public int getNumber() {
 return _number;
 }
public int getHours() {
 return _hours;
 }
@Override
 public String toString() { // to string method to return the data
 return _department + _number;
 }
 }
 b) Problem0789.java :
public class Problem0789 { // class to run the code
public static void main(String[] args) { // driver method
 System.out.println(\"PROBLEM 7\"); // message
Course comp401, comp410, econ410; // object creation for the course class
comp401 = null; // initialise the data
 comp401 = new Course(4, \"COMP\", 401); // pass the data to the constructor
 System.out.println(comp401);// print the data to console
comp410 = null; // initialise the data
 comp410 = new Course(3, \"COMP\", 410); // pass the data to the constructor
 System.out.println(comp410); // print the data to console
econ410 = null; // initialise the data
 econ410 = new Course(3, \"ECON\", 410); // pass the data to the constructor
 System.out.println(econ410); // print the data to console
 }
 }
OUTPUT :
 PROBLEM 7
 COMP401
 COMP410
 ECON410
 Hope this is helpful.


