This is my display interface
public interface Display {
/**
* <p>
* Defines how a display decorates each line</p>
*/
public enum Decorator {
/**
* <p>
* {@code ***}The default string shown around messages</p>
*/
MESSAGE("***"),
/**
* <p>
* {@code ?}The default string shown after a memory location to input an
* instruction</p>
*/
INSTRUCTION("?"),
/**
* <p>
* {@code >>}The default string shown during the execution of a
* simpletron program when requesting for input</p>
*/
INPUT(">>"),
/**
* <p>
* {@code }An empty string</p>
*/
NONE("");
private final String decorator;
private Decorator(String decorator) {
this.decorator = decorator;
}
@Override
public String toString() {
return decorator;
}
}
/**
* <p>
* Display the welcome screen</p>
*/
public void splashScreen();
/**
* <p>
* Displays a message without formatting
* </p>
*
* @param message The message to displayInline
*/
default void show(String message) {
format(message);
}
/**
* <p>
* Displays a message with formatting, works just like the
* {@code String::format method}
* </p>
*
* @param message The message to displayInline
* @param args The
*/
public void format(String message, Object... args);
public static class Messages {
/**
* <p>
* The message that greets the user when they load simpletron</p>
*/
public static final String WELCOME_MESSAGE = "Welcome to Simpletron!\n"
+ "Please enter your program one instruction\n"
+ "(or data word) at a time. I will display\n"
+ "the location number and a question mark (?)\n"
+ "You then type the word for that location.\n"
+ "Type -99999 to stop entering your program.";
public static final String READ = "Enter an integer";
public static final String HALT = "Simpletron execution terminated";
public static final String DIVIDE_BY_ZERO = "Attempt to divide by zero";
public static final String FATAL_ERROR = "Simpletron execution abnormally terminated";
}
}
This is the concrete implementation
public class CommandlineDisplay implements Display {
@Override
public void splashScreen() {
Arrays.stream(Messages.WELCOME_MESSAGE.split("\n")).forEach(line -> format("%s %-43s %s\n", Decorator.MESSAGE, line, Decorator.MESSAGE));
}
@Override
public void format(String message, Object... args) {
System.out.printf(message, args);
}
}
This is the implementation for the system's input
public class CommandlineInput implements Input {
private static final Scanner keyboard = new Scanner(System.in);
@Override
public String nextLine() {
return keyboard.nextLine();
}
}
And last but not least this is the main method
protected void runSystem() {
display.splashScreen();
int index = 0;
int inputValue;
int memorySize = memory.getSize();
while (index < memorySize) {
display.format("%2d %s ", index, Decorator.INSTRUCTION);
inputValue = Integer.parseInt(input.nextLine());
if (inputValue == -99999)
break;
if (inputValue > 9999 || inputValue < -9999)
continue;
memory.set(index++, inputValue);
}
displayMessage("Handling operations");
while (CPU.Register.INSTRUCTION_COUNTER.getValue() < memorySize) {
handleOperation(cpu.execute(memory));
if (CPU.Register.OPERATION_CODE.getValue() < 40)
CPU.Register.INSTRUCTION_COUNTER.setValue(CPU.Register.INSTRUCTION_COUNTER.getValue() + 1);
}
}
The problem I am facing is the command line blocks for input without showing the message from display.format method call, I'm just frustrated I've done basically everything I can think of including changing the input implementation to buffered reader and running with maven, still the same problem