Develop a new application that manages printers devices. (Complete this in JAVA) Your task is to implement two classes ‘LaserPrinter’ and ‘InkjetPrinter’. The application must have four classes:...


Develop a new application that manages printers devices. (Complete this in JAVA)



Your task is to implement two classes ‘LaserPrinter’ and ‘InkjetPrinter’.


The application must have four classes:



  1. Interface ‘IPrinter‘ that must have the headers of the following methods:

    • 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:


    • 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:

    • 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:

    • 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:



  1. import java.util.ArrayList;

  2. public class DriverClass {

  3. public static void main(String[] args) {

  4. ArrayList printers = new ArrayList<>();

  5. // add Laser and Inkjet printers the same ArrayList

  6. printers.add(new LaserPrinter("HP", "H1", 100));

  7. printers.add(new InkjetPrinter("Cannon", "C1", 150));

  8. printers.add(new LaserPrinter("DELL", "D1", 100));

  9. printers.add(new InkjetPrinter("HP", "H2", 50));

  10. // lets test printer 1

  11. //how many pages do we have

  12. System.out.println(printers.get(0));

  13. // send a task to printer 1 with 100 pages

  14. printers.get(0).printPages(100);

  15. // print number of pages the printer can print

  16. System.out.println(printers.get(0));

  17. // lets test printer 2

  18. System.out.println(printers.get(1));

  19. // send a task to printer 1 with 100 pages

  20. printers.get(1).printPages(50);

  21. // print number of pages the printer can print

  22. System.out.println(printers.get(1));

  23. // now lets send a big task to printer 3

  24. printers.get(2).printPages(5000); // rejected: no enough ink

  25. for (Printer printer : printers)

  26. System.out.printf("For printer %s-%s we have printed %d\n",printer.getMaker(),printer.getModel(),printer.getPrintedPageCount());

  27. }

  28. }


Now run the driver class and here is the expected output:



  1. Printer{maker='HP', model='H1', pages Left=2000}

  2. Printer{maker='HP', model='H1', pages Left=1900}

  3. Printer{maker='Cannon', model='C1', pages Left=1666}

  4. Printer{maker='Cannon', model='C1', pages Left=1616}

  5. No enough Ink for the printer DELL-D1

  6. For printer HP-H1 we have printed 100

  7. For printer Cannon-C1 we have printed 50

  8. For printer DELL-D1 we have printed 0

  9. For printer HP-H2 we have printed 0

  10. Process finished with exit code 0

NOTE: PLEASE RESPOND IF YOU CAN SUBMIT ME THE SOLUTION IN EXACTLY OR WITHIN 1 HOUR AND 30 MINUTES FROM NOW.
Nov 23, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here