Question: Develop a new application that manages printers devices. The application must have the following: Interface ' IPrinter ' that must have the headers of the

Develop a new application that manages printers devices. The application must have the following:

  1. Interface 'IPrinter' that must have the headers of the following methods:(0.6m)
    • 'calculatePagesAvailable' that returns int and does not require input parameters
    • 'updateInkLevel' does not return any data and accepts one integer value which is the number of pages
    • 'printPages' does not return any data and accepts one integer value which is the number of pages
  2. Class 'Printer' that must implement the interface 'IPrinter' and the following attributes and methods: (0.6m)
    • Instance variable 'maker' that represents the printer's maker
    • Instance variable 'model' that represents the printer's model
    • Instance variable 'printedPageCount' that represents the number of pages a printer ables to print
    • a two-parameter constructor to initialize the maker and model and set the 'printedPageCount' to zero
    • a method 'printPages' that accepts an integer value that represents the number of pages to be printed. The method adds the input to the 'printedPageCount'
    • a getter for 'printedPageCount'
    • a toString method
    • NOTE: class 'Printer' does not have the implementation of methods: 'calculatePagesAvailable' and 'updateInkLevel'. Those two methods must be implemented by the subclasses of class 'Printer' which are: 'LaserPrinter' and 'InkjetPrinter'
  3. Class 'LaserPrinter' that extends the 'Printer' class and must have: (0.4m)
    • Instance variable 'cartridgeSize' of type double
    • Three-parameter constructor that accepts the make, model and cartridgeSize.
    • Implements the 'calculatePagesAvailable' method that returns the available pages by: cartridgeSize / 0.05
    • Implements the 'updateInkLevel' method that accepts an integer value represents the number of pages currently printed (nPages) and updates the cartridgeSize by: cartridgeSize - (0.05 * nPages)
    • Override the method 'printPages' that accepts an integer value represents the number of pages to be printed and it does the following:
      • if the available number of pages >= the input (number of pages to be printed)
        • add the input to the total number of pages printed so far. Hint: don't repeat yourself, you have this method in the parent class
        • update the ink level
      • otherwise, print a message that says 'no enough ink'
  4. Class 'InkjetPrinter' that extends the 'Printer' class and must have: (0.4m)
    • Instance variable 'inkSize' of type double
    • Three-parameter constructor that accepts the make, mode and inkSize.
    • Implements the 'calculatePagesAvailable' method that returns the available pages by: inkSize / 0.09
    • Implements the 'updateInkLevel' method that accepts an integer value represents the number of pages currently printed (nPages) and updates the inkSize by: inkSize - (0.09 * nPages)
    • Override the method 'printPages' that accepts an integer value represents the number of pages to be printed and it does the following:
      • if the available number of pages >= the input (number of pages to be printed)
        • add the input to the total number of pages printed so far. Hint: don't repeat yourself, you have this method in the parent class
        • update the ink level
      • otherwise, print a message that says 'no enough ink
  5. a Driver class that should get the following code:
import java.util.ArrayList; public class DriverClass { public static void main(String[] args) { ArrayList printers = new ArrayList<>(); // add Laser and Inkjet printers the same ArrayList printers.add(new LaserPrinter("HP", "H1", 100)); printers.add(new InkjetPrinter("Cannon", "C1", 150)); printers.add(new LaserPrinter("DELL", "D1", 100)); printers.add(new InkjetPrinter("HP", "H2", 50)); // lets test printer 1 //how many pages do we have System.out.println(printers.get(0)); // send a task to printer 1 with 100 pages printers.get(0).printPages(100); // print number of pages the printer can print System.out.println(printers.get(0)); // lets test printer 2 System.out.println(printers.get(1)); // send a task to printer 1 with 100 pages printers.get(1).printPages(50); // print number of pages the printer can print System.out.println(printers.get(1)); // now lets send a big task to printer 3 printers.get(2).printPages(5000); // rejected: no enough ink for (Printer printer : printers) System.out.printf("For printer %s-%s we have printed %d ",printer.getMaker(),printer.getModel(),printer.getPrintedPageCount()); } } Expected Output is:
Printer{maker='HP', model='H1', pages Left=2000} Printer{maker='HP', model='H1', pages Left=1900} Printer{maker='Cannon', model='C1', pages Left=1666} Printer{maker='Cannon', model='C1', pages Left=1616} No enough Ink for the printer DELL-D1 For printer HP-H1 we have printed 100 For printer Cannon-C1 we have printed 50 For printer DELL-D1 we have printed 0 For printer HP-H2 we have printed 0 Process finished with exit code 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!