Question 1
In a college, Student s1 chooses a set of courses. Student s2 also chooses all the courses chosen by s1 except the second course, in place of which s2 chooses another course. Write a program that defines two classes Student and Admission. Define a copy constructor to create s2 from s1 such that changing the values of instance variables of either s2 or s1 does not affect the other one. The code takes the name of student s2 and the new course chosen by s2 as input.
- Class
Studenthas/should have the following members.- Private instance variables
String nameandString[] coursesto store the name and the courses chosen, respectively - Define the required constructor(s)
- Accessor methods
getName()andgetCourses(int)to get the name of the student and the course at a specific index, respectively. - Mutator methods
setName(String)andsetCourses(int, String)to set the name of the student and the course at a specific index, respectively.
- Private instance variables
- Class
Admissionhas methodmainthat does the following.- Two objects of
Student,s1ands2, are created.s2is created usings1. - The name of Student
s2and the second course chosen bys2are updated by taking the input. - Finally, the names of
s1ands2and the second course chosen bys1ands2are printed.
- Two objects of
What you have to do:
- Define constructor(s) in class
Student