Question: If you've ever opened your computer's device manager, you've likely seen a whole list of devices, ranging from the obvious (keyboards, printers, monitors) to the
If you've ever opened your computer's device manager, you've likely seen a whole list of devices, ranging from the obvious (keyboards, printers, monitors) to the internal (processors, memory, host controllers), to the subtle (network hosts, laptop lid closing, internal clock). While these devices can fall in a number of categories (input devices, graphics devices, audio devices, etc), they all share some features in common (they all have a name, a device driver, etc). In this section, we will design a very rudimentary implementation of a generic device driver. We are only interested in three things for the time being: the name of the device, an ID number identifying the device, and a flag indicating whether or not it is enabled. Thus, three fields are necessary, a String for the name, a int for the ID, and a boolean for the enabled status.
Any data elements should be declared private. If you think it is necessary you may include helper methods of your own. The class should implement the following public methods:
- public Device(String name, int id) Initialize the device object with the given name and ID. Also, initially the device should not be enabled (the enabled flag should begin as false)
- public final String getName() Retrieves the name of this device. This method is labelled final, meaning that future subclasses cannot change how it behaves.
- public final int getID() Retrieves the ID of this device. This method is also final.
- public String getCategory() Retrieves the specific category of this device, which should be the string "generic"
- public void enable() Sets the state of the device to enabled.
- public void disable() Sets the stae of the device to not enabled.
- public boolean isEnabled() Retrieves the current state of the device.
- @Override public String toString() Returns a string containing the category name, followed by the ID number, followed by a comma and the device name. For example, the followin would be an example of a valid output string: generic 0, x64 processor core
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
