Subject Computer Science Java Programming

Question

Create a stack class for integers.
-Within the stack class, store up to thirty integers.
-Include a push method that adds an integer to the stack.
-Include a pop method that removes an integer from the stack.
-When an integer is popped, use it's position in the stack for the next push.
-Include an isFull method that checks to see if the stack is full.
-Include an isEmpty method that checks to see if the stack is empty.
-Include an output method to display the contents of the stack in LIFO order (the last number pushed should be the first number displayed). Include a message with the display stating what is being displayed. Display the stack on one line with spaces between the numbers.


Create a queue class for integers.
-Within the queue class, store up to thirty integers.
-Include a push method that adds an integer to the queue.
-Include a pop method that removes an integer from the queue.
-When an integer is popped, reorder the queue so that the second integer is now the first, etc. and the last used position will be the next one pushed onto.
-Include an isFull method that checks to see if the queue is full.
-Include an isEmpty method that checks to see if the queue is empty.
-Include an output method to display the contents of the queue in FIFO order (the first number pushed should be the first number displayed). Include a message with the display stating what is being displayed. Display the queue on one line with spaces between the numbers.


Create a demo class that contains the main method.
-Create a stack object and a queue object.
-Inside a loop, create a menu for the user. The choices are:
1. Add a number to the stack.
2. Remove a number from the stack.
3. Display the stack.
4. Add a number to the queue.
5. Remove a number from the queue.
6. Display the queue.
7. Quit.
-If the user chooses options 1 or 4:
       -Check to see if the chosen data structure is full. If it is, display a polite message stating so and display the contents of the chosen data structure.
       -If it is not full, push a random number between 1 and 100 (use Math.random()) onto the chosen data structure and display the number being pushed and the contents of the chosen data structure.
       -Loop back to the menu.
-If the user chooses options 2 or 5:
       -Check to see if the chosen data structure is empty. If it is, display a polite message stating so.
       -If it is not empty, pop a number off of the chosen data structure and display the number being popped and the remaining contents of the chosen data structure.
       -Loop back to the menu.
-If the user chooses options 3 or 6 then display the contents of the chosen data structure and loop back to the menu.
-If the user chooses option 7 then exit the loop.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;


public class demo {


public static void main(String[] args) {
stack test1 = new stack();
queue test2 = new queue();
int option = 0;
int temp;
Scanner in = new Scanner(System.in);
do{
System.out.println("Choices:");
System.out.println("1. Add a number to the stack");
System.out.println("2. Remove a number from the stack");
System.out.println("3. Display the stack");
System.out.println("4. Add a number to the queue");
System.out.println("5. Remove a number from the queue");
System.out.println("6. Display the queue");...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Java Programming Problems
Homework Solution
$30.00
Java
Programming
Computer Science
Arrays
Fractions
Variables
Strings
Numerator
Denominator
Statements
Constructor
Object
Initialization
Java Programming Problems: Expression Trees and AVL Trees
Homework Solution
$50.00
Java
Programming
Computer Science
Expression Trees
AVL Trees
Algorithms
Input
Output
Recursive Functions
Strings
Variables
Statements
Loops
Methods
Expressions
Objects
Classes
Operators
Nodes
Numbers
Java Programming Problems
Homework Solution
$50.00
Computer Science
Java
Programming
Algorithms
Baseball Elimination
Teams
Scores
Players
Flow
New York
American League
Mathematics
Vertices
Artificial Sink
Strings
Sports Division
Edges
Networks
Strings in Java
Homework Solution
$13.00
Computer Science
Programming
Java
Algorithms
ASCII
Summation
Characters
Strings
Unicode Chart
Overloaded Methods
Input
Output
Code Paths
Variables
Statements
Functions
Java Programming Problems
Homework Solution
$15.00
Programming
Computer Science
Java
Payday
Strings
Earnings
Prices
Services
Statements
Variables
Palindromes
Java Programming Questions
Homework Solution
$50.00
Java
Programming
Computer Science
Algorithms
Classes
Shapes
Iterations
Information
Sample Runs
Console Application
Mutator Methods
Colors
User Input
Inheritance
Get help from a qualified tutor
Live Chats