Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cresla;
- import cresla.Manager.ManagerImpl;
- import cresla.interfaces.Manager;
- import cresla.io.Reader;
- import cresla.io.Writer;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Writer writer = new Writer();
- Reader reader = new Reader();
- Manager manager = new ManagerImpl();
- whileloop:
- while (true) {
- String[] tokens = reader.readLine().split("\\s+");
- String command = tokens[0];
- List<String> arguments = Arrays.stream(tokens).skip(1).collect(Collectors.toList());
- String result = "";
- switch (command) {
- case "Reactor":
- result = manager.reactorCommand(arguments);
- break;
- case "Module":
- result = manager.moduleCommand(arguments);
- break;
- case "Report":
- result = manager.reportCommand(arguments);
- break;
- case "Exit":
- result = manager.exitCommand(arguments);
- break whileloop;
- }
- if (!result.isEmpty()) {
- writer.writeLine(result);
- }
- }
- }
- }
- ___________________________________________________________________________________________________________________
- package cresla.Manager;
- import cresla.entities.modules.CooldownSystem;
- import cresla.entities.modules.CryogenRod;
- import cresla.entities.modules.HeatProcessor;
- import cresla.entities.reactors.CryoReactor;
- import cresla.entities.reactors.HeatReactor;
- import cresla.interfaces.AbsorbingModule;
- import cresla.interfaces.EnergyModule;
- import cresla.interfaces.Module;
- import cresla.interfaces.Reactor;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class ManagerImpl implements cresla.interfaces.Manager {
- private int id = 0;
- private Map<Integer, Reactor> reactors;
- private Map<Integer, Module> modules;
- public ManagerImpl() {
- this.id = 1;
- this.reactors = new HashMap<>();
- this.modules = new HashMap<>();
- }
- @Override
- public String reactorCommand(List<String> arguments) {
- String type = arguments.get(0);
- int additionalParameter = Integer.parseInt(arguments.get(1));
- int moduleCapacity = Integer.parseInt(arguments.get(2));
- Reactor reactor = null;
- if (type.equalsIgnoreCase("Cryo")) {
- reactor = new CryoReactor(this.id, additionalParameter, moduleCapacity);
- } else {
- reactor = new HeatReactor(this.id, additionalParameter, moduleCapacity);
- }
- reactors.putIfAbsent(this.id, reactor);
- return String.format("Created %s Reactor - %d", type, this.id++);
- }
- @Override
- public String moduleCommand(List<String> arguments) {
- int reactorId = Integer.parseInt(arguments.get(0));
- String type = arguments.get(1);
- int additionalParameter = Integer.parseInt(arguments.get(2));
- Module module = null;
- if (type.equalsIgnoreCase("CryogenRod")) {
- module = new CryogenRod(this.id, additionalParameter);
- reactors.get(reactorId).addEnergyModule((EnergyModule) module);
- } else if (type.equalsIgnoreCase("HeatProcessor")) {
- module = new HeatProcessor(this.id, additionalParameter);
- reactors.get(reactorId).addAbsorbingModule((AbsorbingModule) module);
- } else if (type.equalsIgnoreCase("CooldownSystem")) {
- module = new CooldownSystem(this.id, additionalParameter);
- reactors.get(reactorId).addAbsorbingModule((AbsorbingModule) module);
- }
- modules.putIfAbsent(this.id, module);
- return String.format("Added %s - %d to Reactor - %d", type, this.id++, reactorId);
- }
- @Override
- public String reportCommand(List<String> arguments) {
- return null;
- }
- @Override
- public String exitCommand(List<String> arguments) {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement