Java Programming
stack calculator or cellar memory is an abstract data structure that is structured like a list. In the case of a stack, it is only possible to add a new element at the first position
INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS
JAVA ASSIGNMENT 3
Do not use any elements of the Java libraries, except elements of java.lang and java.io packages.
Exercise A and B need to be submitted separately.
- STACK BASED CALCULATOR (Note: Only use LinkedList for this exercise. Do not use ArrayList)
A stack or cellar memory is an abstract data structure that is structured like a list. In the case of a stack, it is only possible to add a new element at the first position, to remove the last added element or to return the value of the last added value. The internal structure of the stack is hidden from the user - they can only add and remove elements. However, the user should have access to further information, such as a textual representation and the size of the stack.
A pocket calculator uses a stack as a storage model, i.e. numbers can be added one after the other and mathematical operations can be carried out. The top two numbers are always taken from the stack and the result of the operation is placed on the stack. The goal of the task is to develop an interactive user interface that enables interaction with the calculator with integers. Make sure there is a clear separation between the user interface, the logic of the calculator and the stack. Implement the following commands. Your program should be able to process the specified entries and output an error message (starting with Error, ␣) in the (specified possible) error cases. If the entry is valid, the specified output should be output. If an unknown command is entered, an error message is issued.
Note: You can assume that transferred numbers can always be converted into integers without errors.
- push <number>
- number: Input an integer
- Functionality: puts number on the stack of the calculator
- Output: OK
- Possible errors:
- Invalid number of arguments
- Symbol in parameter number, which is not a number
- pop
- Functionality: removes the first element of the stack. If the stack is empty, the stack does not change.
- Output: OK
- Possible error case: invalid number of arguments
- peek
- Functionality: Outputs the top element of the stack and does not change the stack.
- Output: The string representation of the topmost element of the stack
- possible errors:
- invalid number of arguments
- the stack is empty
- add
- Functionality: Adds the top two elements of the stack and places the result on the stack.
- Output: OK
- possible errors:
- invalid number of arguments
- the stack has less than 2 elements
- sub
- Functionality: Subtracts the second top element from the topmost element and sets the result on the stack.
- Output: OK
- possible errors:
- invalid number of arguments
- the stack has less than 2 elements
- multiply
- Functionality: Multiplies the top two elements of the stack and places the result on the stack.
- Output: OK
- possible errors:
- invalid number of arguments
- the stack has less than 2 elements
- divide
- Functionality: divides the top element by the second top element and puts the result (as an integer) on the stack.
- Output: OK
- possible errors:
- invalid number of arguments
- the stack has less than 2 elements
- the second top element is a 0
- if-else
- Functionality: takes the top element from the stack; if this is a 0, the second top element is removed from the stack. Otherwise, the third top element is removed from the stack. The top element remains on the stack.
- Output: OK
- possible errors:
- invalid number of arguments
- the stack has less than 3 elements
- print
- Functionality: Outputs a textual representation of the stack. The individual elements are separated by commas (without spaces). Output begins at the top of the stack. If the stack is empty, an empty line is simply output.
- Output: <top element>,<second top element>,...,<bottom element>
- Possible error case: invalid number of arguments
- revert
- Functionality: Inverts the stack so that, for example, the top element is the bottom element. i.e the stack 1,2,3 becomes 3,2,1. If the stack is empty, the stack does not change.
- Output: OK
- Possible error case: invalid number of arguments
- reset
- Functionality: Completely empties the calculator's memory
- Output: OK
- Possible error case: invalid number of arguments
12.quit
- Functionality: exits the program
- Output: no output
- Possible error case: invalid number of arguments
Related Questions
. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java
CS 340 Milestone One Guidelines and Rubric
Overview: For this assignment, you will implement the fundamental operations of create, read, update,
. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class
Retail Transaction Programming Project
Project Requirements:
Develop a program to emulate a purchase transaction at a retail store. This
. The following program contains five errors. Identify the errors and fix them
7COM1028
Secure Systems Programming
Referral Coursework: Secure
. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer
CS 340 Final Project Guidelines and Rubric
Overview The final project will encompass developing a web service using a software stack and impleme