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

Java program What you need to do You will need to implement the following classe

ID: 3860727 • Letter: J

Question

Java program

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 printInventory() method that prints each electronic device on the
"devices" array on a separate line, based on the results that getSummary()
returns for that device
• Computer (an abstract class that imlpements the ElectronicDevice interface), with the
following:
o Private internal variables: name (String) and storage (int).
o 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 getOperatingSystem() 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
reference to a Computer to save the data to. It returns nothing.
• AppleMacbook (a concrete type of Computer)
o Runs the "OS X" operating system
• DellDesktop (a concrete type of Computer)
o Runs the "Windows" operating system
• EpsonPrinter (a concrete type of Computer that also can act as a Printer)
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

Explanation / Answer

Below are the required iterfaces and classes (questions says check output below but there is not ouput screen in the question, I implement methods and you can easily modify them) (rate if satisfied else comment)

ElectronicDevice.java

package temp;

public interface ElectronicDevice {

public String getSummary();

}

PowerSource.java

package temp;

public class PowerSource {

private ElectronicDevice[] devices;

public PowerSource(ElectronicDevice[] device) {

devices = new ElectronicDevice[6];

this.devices = device;

}

/**

* takes any kind of Electronic device and adds it to the "devices" array.

*

* @param eDevice

*/

public void attach(ElectronicDevice eDevice) {

for (int i = 0; i < devices.length; i++) {

if (devices[i] == null) {

devices[i] = eDevice;

}

}

}

/**

* method that prints each electronic device on the "devices" array on a

* separate line, based on the results that getSummary() returns for that

* device

*/

public void printInventory() {

for (int i = 0; i < devices.length; i++) {

if (devices[i] != null) {

devices[i].getSummary();

}

}

}

}

Computer.java

package temp;

public abstract class Computer implements ElectronicDevice {

private String name;

private int storage;

public Computer(String name, int storage) {

this.name = name;

this.storage = storage;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getStorage() {

return storage;

}

public void setStorage(int storage) {

this.storage = storage;

}

public void save(int storage) {

this.storage = this.storage - storage;

}

/**

* Abstract method

*

* @return

*/

public abstract String getOperatingSystem();

@Override

public String getSummary() {

String temp = "This computer, " + name + " has " + storage + " units of memory";

return temp;

}

}

Printer.java

package temp;

public interface Printer extends ElectronicDevice {

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

public void print(String jobName, int pages);

}

AppleMacBook.java

package temp;

public class AppleMacbook extends Computer{

public AppleMacbook(String name, int storage) {

super(name, storage);

}

@Override

public String getOperatingSystem() {

// TODO Auto-generated method stub

return "OS X";

}

}

DellDesktop.java

package temp;

public class DellDesktop extends Computer {

public DellDesktop(String name, int storage) {

super(name, storage);

}

@Override

public String getOperatingSystem() {

return "Windows";

}

EpsonPrinter.java

package temp;

public class EpsonPrinter extends Computer implements Printer {

public EpsonPrinter(String name, int storage) {

super(name, storage);

}

/**

* Scan method

*/

@Override

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

if (computer.getStorage() >= pages * 5) {

String temp = "Scanned " + jobName + ", pages:" + String.valueOf(pages) + ", from " + computer.getName();

System.out.println(temp);

} else {

System.out.println("Each page scan requires atleast 5 units of storage on target computer");

}

}

/**

* Print method

*/

@Override

public void print(String jobName, int pages) {

String temp = "Printed " + jobName + ", pages:" + String.valueOf(pages);

System.out.println(temp);

}

@Override

public String getOperatingSystem() {

return "Linux";

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote