Question 1
Write Java code that gives a simple demonstration of how a set of student registration requests is processed in a department of a college. It accepts a specific number of seats as input, and prints whether the registration is successful or not, based on the remaining seats left. The code uses the concept of inner classes, and has the following components:
- Interface
Registerablehas an abstract methodregister(). - Class
Departmentwith:- Instance variable
name(String) representing the department name - Constructor to initialize the instance variable
- An inner private class
DeptEnquirythat has/does the following:reqseats,avalseatsas instance variables that hold the number of requested seats and available seats, respectively.- Implements interface
Registerable(whose methodregisterreturns a string that describes whether registration is successful or not), which enables its object to be accessible from outside the classDepartment. - Constructor to initialize the instance variables
- Method
public String register()checks whetheravalseatsis less thanreqseats. If it is less, then it returnsCannot register, else it returnsRegistered successfully available seats are <available seats>.
- Method
enrollRequest(int)that takes the number of seats to be registered as an argument and returns aRegisterableobject on which methodregister()can be invoked.
- Instance variable
- Class
Studenthas methodmainthat does the following:- Creates an object of
Departmentwith the nameDCSE. Using this object, it invokes methodenrollRequestto obtain aRegisterableobject, and invokes methodregisteron it.
- Creates an object of
What you have to do:
- Define method
enrollRequest()in classDepartment