AlgoMaster Logo
AlgoMasterStart a Computereasy

Start a Computer

easy

A computer starts through three small subsystems: the power supply comes on, the system drive mounts, and the network connects. A facade gives callers one startup operation and one safe reverse-order shutdown operation.

Implement only the ComputerFacade class:

  • String[] startComputer() powers on, mounts the disk, and connects the network. It returns a header, the three subsystem responses, and a footer in that order.
  • String[] shutDown() disconnects the network, unmounts the disk, and powers off. It returns a header, the three subsystem responses, and a footer in that order.
  • String setNetwork(boolean connected) connects or disconnects by delegating to the network adapter.
  • String setDisk(boolean mounted) mounts or unmounts by delegating to the disk drive.
  • boolean powerOn(), boolean diskMounted(), and boolean networkConnected() query the corresponding subsystem.
  • int startupCount() returns how many times startComputer has run.

The supplied PowerSupply, DiskDrive, and NetworkAdapter classes, along with the public FacadeDriver test harness, are complete in the starter code. Implement only ComputerFacade; do not modify the supplied types. The examples use FacadeDriver operations because that is the class the tests instantiate. The operations are idempotent: asking an already-on device to turn on returns the same line and keeps it on.

Example 1:

Input:

Output:

Example 2:

Input:

Output:

Constraints

  • At most 100 calls are made across all methods.

Starter Code

Only ComputerFacade is unfinished. The supporting subsystem classes and FacadeDriver test harness are pre-implemented; do not modify them.

How the design is graded

needs 7/10 to pass
  • Startup and shutdown sequences

    Full marks when startComputer powers on, mounts the disk, and connects the network in that order, and shutDown disconnects the network, unmounts the disk, and powers off in reverse order. Lose points when a step is skipped, reordered, or replaced by text written in the facade.

  • Subsystems own their state

    Full marks when the three query methods ask their supplied subsystem and the two direct setters reuse subsystem operations. Lose points when the facade keeps duplicate booleans or bypasses a subsystem.

  • Facade-owned counter

    Full marks when startupCount increases once for each startComputer call and never changes for shutdown or direct calls. Lose points for counting individual subsystem operations or printing instead of returning responses.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new FacadeDriver()null
startComputer()["--- Starting computer ---","Power: Supply on.","Disk: System drive mounted.","Network: Connected.","--- Computer ready. ---"]
powerOn()true
diskMounted()true
networkConnected()true
startupCount()1

The single startup call reaches the three subsystems in dependency order, and every query reads the resulting subsystem state.

Run checks these cases. Submit also runs a larger hidden set.