You will be constructing a series of elecrtonic devices and integrating them in a short program. You should heavily use abstract classes and interfaces.

What you need to do

You will need to implement the following classes/interfaces, obeying the following (but there may be more you need to do, based on ComputerLand code):

  • PowerSource (a concrete class), which supports the following:
    • Holds up to 6 ElectronicDevice objects (in an array)
    • An attach() method, per use in ComputerLand
    • Has a printInventory() method that calls getSummary() on all its devices
  • ElectronicDevice (an interface), with the following
    • A getSummary(), as used in PowerSource (see below), returns a String
  • Computer (an abstract class that is a type of ElectronicDevice), with the following:
    • 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).
    • Can be associated with a Printer, as shown in ComputerLand code
    • Must support a save() method that takes an amount of storage needed and decrements the storage available (no filenames required).
    • Has an abatract method called getOperatingSystem() that returns a String
    • Implements getSummary()
  • Printer (an interface that is a type of ElectronicDevice)
    • Supports print() method that takes a jobName (String) and number of pages (int). It returns nothing
    • 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)
    • Has "OS X" operating system
  • DellDesktop (a concrete type of Computer)
    • Has "Windows" operating system
  • EpsonPrinter (a concrete type of Computer that also can act as a Printer)
    • Every page virtually scanned requires 5 storage units on target computer
    • Logs each virtual scan to output (see below)
    • Logs each page virtually printed (as it is printed) to output (see below)
    • Has "Linux" operating system
  • ComputerLand (included, see below)

You must combine your work with the following:

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 areement", 2);
source.printInventory();
}
}

so that the following is produced (exactly) when ComputerLand is run:

Scanning 10 pages of Passport application to MyMac
Printing page 0 of Story
Printing page 1 of Story
Printing page 2 of Story
Printing page 3 of Story
Printing page 4 of Story
Scanning 25 pages of Taxes to MyDell
Printing page 0 of License areement
Printing page 1 of License areement
=== INVENTORY ===
MyMac (running OS X) with storage=950
MyDell (running Windows) with storage=375
MyEpson (running Linux) with storage=2
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.