Question
Using Java Create a parent class Tech and 2 child classes Bind and Mond Tech Task: public Device(String name, int id) Initialize the device object
Using Java
Create a parent class Tech and 2 child classes Bind and Mond
Tech Task:
- 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
Bind task:
Write a Disk device, which is more specific than a generic device, and thus Disk should extend Device. Since we are extending the class, it will automatically inherit all of the functionality of the Device class. We will just add some specifics associated with disks - the notion of disk size, which should be stored as a long because disk sizes can be relatively large.
- public Disk(String name, int id, long size) Initialize the device with the given name, ID, and now disk size. Be sure to use the parent class's constructor for part of this, because it's the only way you'll be able to initialize the parent's fields.
- @Override public String getCategory() This should return the value "disk"
- public long getSize() Retrieves the size of the disk in bytes.
- @Override public String toString() Returns the same result as the Device's version of toString() with the addition of the size in bytes in parenthesis. So for example,
disk 1, 7500rpm HDD (1099511627776 bytes)
Mond task:
Write a Printer device, which also derives from generic devices, but this time includes the notion of jobs to be printed. Like Disk, a Printer should extend from Device. Additionally, a Printer should have an int which represents the number of jobs currently in the printer's print queue. We can add or complete print jobs, or check the number currently in the queue, but for this assignment that is the extent of what we expect (we will not be passing full-fledged print jobs to the class, we will just keep track of the number of jobs).
- public Printer(String name, int id) Initializes the device with name and ID as before. Make sure to use the parent's constructor, otherwise the parent's fields will not be set. Additionally, the number of print jobs should initially be set to zero.
- @Override public String getCategory() This should return the value "printer".
- @Override public void disable() Whenever a printer device is disabled, the number of active print jobs should be reset to zero, in addition to anything that the disable()method was already doing in the parent class.
- public void submitJob() Increase the number of print jobs by one, but only if the printer device is currently enabled.
- public int numJobs() Report the number of currently active print jobs.
- public void completeJob() Complete one of the currently active print jobs (i.e. reduce the number of jobs by one if there are more than zero jobs to print).
- Below is a sample run demonstrating how the class would function using the following input: 1 abc 2.0 3 def 4.0 6 7 xyz 5.5
Thanks in advance. I will rate u five stars if u do all the requirements
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started