I'm working on a Von Neumann Machine, I'm writing a java program that works like a simple machine, that follows instructions. It reads a textfile and depending on the OpCode in the file, it either stores, adds, substract, multilply, divide and load numbers. Should I use a switch statement or alot of if else statements?
- 01 07 // load 7 to Accumulator
- 21 91 // store Accumulator M1
- 05 13 // add 13 to 7 and keep 20 in the Acc.
- 99 99 // print Acc. contents
- 06 12 // subtract 12 from Acc.
21 91 // store 8 to M1
public class Machine{ public static void main(String[] args) throws FileNotFoundException
{
File file = new File("U:/op.txt"); Scanner readfile = new Scanner(file); while(readfile.hasNextInt()){ String read = readfile.nextLine(); System.out.println(read); } }