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
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
Related questions
Question
please help!!
(with a screenshot of the code for this, not typed on here, because it gives me errors)
Java
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 5 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education