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 operand Рop 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, t2 = pop(), t1 = pop(), t3 = t1 – t2, push(t3). Mul Div Requirements 1. The program must be written 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 1. Java's Stack class works great for this. Google “Java stack class" for documentation and examples. 2. 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']. Upload: Your Java source file (.java) Sample machine.txt Push Sample Output 2.5 Stored in location MO 2.5 5.5 Stored in location M1 Роp MO Push 3.0 4.5 Stored in location M2 17.27 Stored in location M3 Push MO 8.635 Stored in location M4 Add Pop M1

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please help!!

(with a screenshot of the code for this, not typed on here, because it gives me errors)

Java

 

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
stack. Note that the value that was pushed first comes first in the operation. Sub works like this,
t2 = pop(), t1 = pop(), t3 = t1 – t2, push(t3).
Sub
Mul
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
1. Java's Stack class works great for this. Google "Java stack class" for documentation and
examples.
2. 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'].
Upload: Your Java source file (.java)
Sample machine.txt
Sample Output
Push
2.5
2.5 Stored in location MO
Рop
MO
5.5 Stored in location M1
Push
3.0
4.5 Stored in location M2
17.27 Stored in location M3
Push
MO
8.635 Stored in location M4
Add
Рор
M1
Transcribed Image Text: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 stack. Note that the value that was pushed first comes first in the operation. Sub works like this, t2 = pop(), t1 = pop(), t3 = t1 – t2, push(t3). Sub Mul 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 1. Java's Stack class works great for this. Google "Java stack class" for documentation and examples. 2. 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']. Upload: Your Java source file (.java) Sample machine.txt Sample Output Push 2.5 2.5 Stored in location MO Рop MO 5.5 Stored in location M1 Push 3.0 4.5 Stored in location M2 17.27 Stored in location M3 Push MO 8.635 Stored in location M4 Add Рор M1
Push
М1
Push
1.0
Sub
Рop
M2
Push
3.14
Push
M1
Mul
Рop
МЗ
Push
M3
Push
2.0
Div
Рop
М4
Machine.txt down below
Push
2.5
Роp
мо
Push
3.0
Push
мо
Add
Рop
M1
Push
M1
Push
1.0
Sub
Роp
M2
Push
3.14
Push
M1
Mul
Роp
M3
Push
M3
Push
2.0
Div
Роp
М4
Transcribed Image Text:Push М1 Push 1.0 Sub Рop M2 Push 3.14 Push M1 Mul Рop МЗ Push M3 Push 2.0 Div Рop М4 Machine.txt down below Push 2.5 Роp мо Push 3.0 Push мо Add Рop M1 Push M1 Push 1.0 Sub Роp M2 Push 3.14 Push M1 Mul Роp M3 Push M3 Push 2.0 Div Роp М4
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education