Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use JAVA only Write a Printer device, which also derives from generic devices, but this time includes the notion of jobs to be printed.

Please use JAVA only

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 intwhich 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).

The class should implement the following public methods:

  • 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).

Example:

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

> Device dev = new Device("controller", 0); > System.out.println(dev); generic 0, controller > dev.isEnabled() false > dev.enable(); > dev.isEnabled() true > Disk disk = new Disk("HDD", 1, 123456789); > System.out.println(disk); disk 1, HDD (123456789 bytes) > disk.getSize() 123456789 > disk.enable(); > disk.isEnabled() true > Disk disk2 = new Disk("SDD", 2, 256000000000L); > Printer p = new Printer("Laser Printer", 3); > p.numJobs() 0 > p.submitJob(); > p.numJobs() 0 > p.isEnabled() false > p.enable(); > p.submitJob(); > p.numJobs() 1 > p.submitJob(); > p.numJobs() 2 > p.completeJob(); > p.numJobs() 1 > p.completeJob(); > p.completeJob(); > p.numJobs() 0 > Device[] devices = {dev, disk, disk2, p}; > for (Device d : devices) { System.out.println(d); } generic 0, controller disk 1, HDD (123456789 bytes) disk 2, SDD (256000000000 bytes) printer 3, Laser Printer

  • Please make sure that it passes the following: https://repl.it/@micky123/ColorfulGranularCode

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Define Management or What is Management?

Answered: 1 week ago

Question

What do you understand by MBO?

Answered: 1 week ago