Question: Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6
Please help with program this. Thank you so much in advance!



Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs the operation, then pushes the result on the Sub stack. Note that the value that was pushed first comes first in the operation. Sub works like this, Mul t2 pop(), t1 pop(), t3 t1 - t2, push(t3) Div Requirements 1. The program must be written in Java. It may implement its own stack, or it may use the Java API Stack class. Only floating point values are stored on the stack and in memory 2. The instructions are read from the machine.txt file. 3. In addition to moving a value from the stack to memory, the Pop operation must display a message on the console. 4. This program does not have to deal with error conditions like stack underflow or invalid input 5. The program needs work for any valid input file. The instructor will test it with data that is different from this sample data Hints Java's Stack class works great for this. Google "Java stack class" for documentation and examples You can use the second character as an index into an array which holds your 10 memory locations., like this, Memory[str.charAt (1) -'0'] 1. 2. Upload: Your Java source file (.java) Sample machine.txt Push 2.5 Pop MOo Push 3.0 Push MO Add Pop M1 Sample Output 2.5 Stored in location MO 5.5 Stored in location M1 4.5 Stored in location M2 17.27 Stored in location M3 8.635 Stored in location M4 Push M1 Push 1.0 Sub Pop M2 Push 3.14 Push M1 Mul Pop M3 Push M3 Push 2.0 Div Pop M4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
