Consider a superclass Course and three subclasses: ComputerScience, Math and Eng
ID: 3584471 • Letter: C
Question
Consider a superclass Course and three subclasses: ComputerScience, Math and English. What instance data and methods should be declared in Course and in each of the three subclasses? Come up with at least 1 instance data unique to each of the four classes. Recall that all instance data of Course will be inherited by the subclasses. Also, come up with the accessor and mutator methods for each class. You only have to provide their signatures, you do not have to provide the code for these methods. Be sure to include a one-line description for each instance data and method to explain what they do. In your design, think about: computer accounts, TAs, lab sections, tutorial sections, lecture times, types of assignments, required equipment (e.g., calculator), etc. Hint: All courses have an instructor. Computer Sciencc and Math have labs but English doesn't.Explanation / Answer
class Course { String name; String courseId; Course(String name1, String courseId1) { name = name1; courseId = courseId1; } void Display() { System.out.println("course Name : " + name); System.out.println("course id : " + courseId); } } class ComputerScience extends coourse { int id; String instructor; String classroom; Student(String name1, String courseId1, int nId, String instr,String clsrm ) { super(name1,courseId1); id = nId; instructor = instr; classroom=clsrm; } void Display() { super.Display(); System.out.println("ID : " + id); System.out.println("Instructor : " + instructor); System.out.println("Class room : " + classroom); } } class Math extends Course { int id; String instructor; String classroom; Math(String name1, String courseId1, int nId, String instr,String clsrm) { super(name1,courseId1); d = nId; instructor = instr; classroom=clsrm; } void Display() { super.Display(); System.out.println("ID : " + id); System.out.println("Instructor : " + instructor); System.out.println("Class room : " + classroom); } } class English extends Course { int id; String instructor; String classroom; English(String name1, String courseId1, int nId, String instr,String clsrm) { super(name1,courseId1); d = nId; instructor = instr; classroom=clsrm; } void Display() { super.Display(); System.out.println("ID : " + id); System.out.println("Instructor : " + instructor); System.out.println("Class room : " + classroom); } } class InheritanceDemo { public static void main(String args[]) { Course co = new Course("b.tech","124450"); ComputerScience cs = new ComputerScience("CS","2133",1,"Roma","1 - B"); Math mat = new Math("MATH","2134",2,"John","1 - C"); English en = new English("ENGLISH","2135",3,"Jake","1 - D"); System.out.println("Course :"); co.Display(); System.out.println(""); System.out.println("Computer science :"); cs.Display(); System.out.println(""); System.out.println("mathematics :"); mat.Display(); System.out.println(""); System.out.println("English :"); en.Display(); } }