Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use java language What you need to do You will need to implement the following c

ID: 3860705 • Letter: U

Question

Use java language What you need to do You will need to implement the following classes/interfaces, obeying the following: ElectronicDevice (an interface), with the following o A getSummary) method that returns a String PowerSource (a concrete class), which supports the following o Holds up to 6 ElectronicDevice objects in a private array named "devices" o An attach) method that takes any kind of Electronic device and adds it to the "devices" array o Has a printlnventory) method that prints each electronic device on the "devices" array on a separate line, based on the results that getSummary0 returns for that device .Computer (an abstract class that imlpements the ElectronicDevice interface), with the following o o Private internal variables: name (String) and storage (int). Constructor that takes name (String) and storage (int) as parameters. The storage parameter is just a number, there are no units (like GB or MB) o Can be associated with a Printer, as shown in ComputerLand code o Must support a save) method that takes an amount of storage needed, as a parameter, and decrements the storage available (no filenames required). o Has an abatract method called getOperatingSystem0 that returns a String o Provides an implementation of getSummary) (see example output below) Printer (an interface that is a type of ElectronicDevice) o Supports print) method that takes a jobName (String) and number of pages (int). It returns nothing o Supports a scan) method that takes a jobName, number of pages to scan, and AppleMacbook (a concrete type of Computer) DellDesktop (a concrete type of Computer) EpsonPrinter (a concrete type of Computer that also can act as a Printer) reference to a Computer to save the data to. It returns nothing o Runs the "OS X" operating system o Runs the "Windows" operating system o Every page virtually scanned requires 5 storage units on target computer o Logs each virtual scan to output (see below) o Logs each page virtually printed (as it is printed) to output (see below) o Has "Linux" operating system .ComputerLand (included, see below)

Explanation / Answer

PROGRAM CODE:

ElectronicDevice.java

package electronicdevices;

public interface ElectronicDevice {

  

   public String getSummary();

}

PowerSource.java

package electronicdevices;

public class PowerSource {

  

   private ElectronicDevice devices[];

   private int count;

  

   public PowerSource() {

       devices = new ElectronicDevice[6];

       count = 0;

   }

  

   public void attach(ElectronicDevice device)

   {

       devices[count++] = device;

   }

  

   public void printInventory()

   {

       System.out.println("=== INVENTORY ===");

       for(int i=0; i<count; i++)

           System.out.println(devices[i].getSummary());

   }

}

Computer.java

package electronicdevices;

public abstract class Computer implements ElectronicDevice{

  

   private String name;

   private int storage;

   private Printer printer;

  

   public Computer(String name, int storage) {

       this.name = name;

       this.storage = storage;

   }

  

   public void save(int space)

   {

       storage -= space;

   }

  

   public void addPrinter(Printer printer)

   {

       this.printer = printer;

   }

  

   public void print(String jobName, int numPages)

   {

       printer.print(jobName, numPages);

   }

   public void scan(String jobName, int numPages)

   {

       printer.scan(jobName, numPages, this);

   }

   public String getName()

   {

       return name;

   }

  

   public int getStorage()

   {

       return storage;

   }

   public abstract String getOperatingSystem();

  

   @Override

   public String getSummary() {

      

       return name + " (running " + getOperatingSystem() + ") with storage=" + storage;

   }

}

Printer.java

package electronicdevices;

public interface Printer extends ElectronicDevice{

       public void print(String jobName, int numPages);

       public void scan(String jobName, int numPages, Computer computer);

}

AppleMacbook.java

package electronicdevices;

public class AppleMacbook extends Computer{

   public AppleMacbook(String name, int storage) {

       super(name, storage);

   }

   @Override

   public String getOperatingSystem() {

       return "OS X";

   }

  

}

DellDesktop.java

package electronicdevices;

public class DellDesktop extends Computer{

   public DellDesktop(String name, int storage) {

       super(name, storage);

      

   }

   @Override

   public String getOperatingSystem() {

      

       return "Windows";

   }

}

EpsonPrinter.java

package electronicdevices;

public class EpsonPrinter extends Computer implements Printer{

   public EpsonPrinter(String name, int storage) {

       super(name, storage);

   }

   @Override

   public void print(String jobName, int numPages) {

       for(int i=1; i<=numPages; i++)

       {

           System.out.println("Printing page " + i + " of " + jobName);

       }

   }

   @Override

   public void scan(String jobName, int numPages, Computer computer) {

       System.out.println("Scanning " + numPages + " pages of " + jobName + " to " + computer.getName());

       for(int i=1; i<=numPages; i++)

       {

           computer.save(5);

       }

      

      

   }

   @Override

   public String getOperatingSystem() {

       return "Linux";

   }

}

ComputerLand.java

package electronicdevices;

public class ComputerLand {

   public static void main(String[] args) {

      

       Computer mac = new AppleMacbook("MyMac", 1000);

       Computer dell = new DellDesktop("MyDell", 500);

      

       Printer epson = new EpsonPrinter("MyEpson", 2);

      

       PowerSource source = new PowerSource();

      

       source.attach(mac);

       source.attach(dell);

       source.attach(epson);

      

       mac.addPrinter(epson);

       dell.addPrinter(epson);

      

       mac.scan("Passport Application", 10);

       mac.print("Story", 5);

      

       dell.scan("Taxes", 25);

       dell.print("License Agreement", 2);

      

       source.printInventory();

   }

}

OUTPUT:

Scanning 10 pages of Passport Application to MyMac

Printing page 1 of Story

Printing page 2 of Story

Printing page 3 of Story

Printing page 4 of Story

Printing page 5 of Story

Scanning 25 pages of Taxes to MyDell

Printing page 1 of License Agreement

Printing page 2 of License Agreement

=== INVENTORY ===

MyMac (running OS X) with storage=950

MyDell (running Windows) with storage=375

MyEpson (running Linux) with storage=2