Implementing Stack and Queue by Using Array; (Two Separate programs)
Part A)
A stack is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored in order of insertion and the elements are removed in reverse order. Because the last element that is inserted is the first to be removed, it is often referred to as a Last-in First-out (LIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyStack interface specifies the operations that any implementation of a stack must have such as Push and Pop.
2) Write your concrete class to implement your MyStack interface. In this class add methods to set and get size of the stack. Class must also set the default size and maximum size of the stack. It must also control the flow of the stack by giving messaging such as \"Stack is empty\" or \"Stack is underflow\", \"Stack is overflow\" or \"Full\", when user is trying to push more item in the stack when it is already full.
3) Write a test program to use your concrete class. To test your class set your stack maximum size to 10. Ask from the user to enter Student Name and then store in the stack. Your main program must offer the following options to the user;
1) Set Maximum size of the Stack (it must show the stack maximum limit)
2) Push (Add student name to the stack)
3) Pop (Take out student name from the stack)
4) PopUpAll (Display all student names in the stack, after this stack will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
Part B)
A Queue is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored at the back end and elements are removed from the front end. it is often referred to as a First-In First-Out (FIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyQueue interface specifies the operations that any implementation of a Queue must have such as Insert and Delete.
2) Write your concrete class to implement your MyQueue interface. In this class add methods to set and get size of the Queue. Class must also set the default size and maximum size of the Queue. It must also control the flow of the Queue by giving messaging such as \"Queue is empty\" or \"Queue is underflow\", \"Queue is overflow\" or \"Full\", when user is trying to Add/insert more item in the Queue when it is already full.
3) Write a test program to use your concrete class. To test your class set your Queue maximum size to 10. Ask from the user to enter Student Name and then store in the Queue. Your main program must offer the following options to the user;
1) Set Maximum size of the Queue (it must show the Queue maximum limit)
2) Add/Insert (Add student name to the Queue)
3) Delete (Take out student name from the Queue)
4) DeleteAll (Delete and Display all student names in the Queue, after this Queue will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
I need a java program, a JAVA PROGRAM. please
Implementing Stack and Queue by Using Array; (Two Separate programs)
Part A)
A stack is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored in order of insertion and the elements are removed in reverse order. Because the last element that is inserted is the first to be removed, it is often referred to as a Last-in First-out (LIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyStack interface specifies the operations that any implementation of a stack must have such as Push and Pop.
2) Write your concrete class to implement your MyStack interface. In this class add methods to set and get size of the stack. Class must also set the default size and maximum size of the stack. It must also control the flow of the stack by giving messaging such as \"Stack is empty\" or \"Stack is underflow\", \"Stack is overflow\" or \"Full\", when user is trying to push more item in the stack when it is already full.
3) Write a test program to use your concrete class. To test your class set your stack maximum size to 10. Ask from the user to enter Student Name and then store in the stack. Your main program must offer the following options to the user;
1) Set Maximum size of the Stack (it must show the stack maximum limit)
2) Push (Add student name to the stack)
3) Pop (Take out student name from the stack)
4) PopUpAll (Display all student names in the stack, after this stack will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
Part B)
A Queue is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored at the back end and elements are removed from the front end. it is often referred to as a First-In First-Out (FIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyQueue interface specifies the operations that any implementation of a Queue must have such as Insert and Delete.
2) Write your concrete class to implement your MyQueue interface. In this class add methods to set and get size of the Queue. Class must also set the default size and maximum size of the Queue. It must also control the flow of the Queue by giving messaging such as \"Queue is empty\" or \"Queue is underflow\", \"Queue is overflow\" or \"Full\", when user is trying to Add/insert more item in the Queue when it is already full.
3) Write a test program to use your concrete class. To test your class set your Queue maximum size to 10. Ask from the user to enter Student Name and then store in the Queue. Your main program must offer the following options to the user;
1) Set Maximum size of the Queue (it must show the Queue maximum limit)
2) Add/Insert (Add student name to the Queue)
3) Delete (Take out student name from the Queue)
4) DeleteAll (Delete and Display all student names in the Queue, after this Queue will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
I need a java program, a JAVA PROGRAM. please
Implementing Stack and Queue by Using Array; (Two Separate programs)
Part A)
A stack is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored in order of insertion and the elements are removed in reverse order. Because the last element that is inserted is the first to be removed, it is often referred to as a Last-in First-out (LIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyStack interface specifies the operations that any implementation of a stack must have such as Push and Pop.
2) Write your concrete class to implement your MyStack interface. In this class add methods to set and get size of the stack. Class must also set the default size and maximum size of the stack. It must also control the flow of the stack by giving messaging such as \"Stack is empty\" or \"Stack is underflow\", \"Stack is overflow\" or \"Full\", when user is trying to push more item in the stack when it is already full.
3) Write a test program to use your concrete class. To test your class set your stack maximum size to 10. Ask from the user to enter Student Name and then store in the stack. Your main program must offer the following options to the user;
1) Set Maximum size of the Stack (it must show the stack maximum limit)
2) Push (Add student name to the stack)
3) Pop (Take out student name from the stack)
4) PopUpAll (Display all student names in the stack, after this stack will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
Part B)
A Queue is an abstract data type that allows only a limited number of operations on a collection of data. Elements are stored at the back end and elements are removed from the front end. it is often referred to as a First-In First-Out (FIFO) collection. For this assignment complete the following requirements;
1) create a new interface with the name MyQueue interface specifies the operations that any implementation of a Queue must have such as Insert and Delete.
2) Write your concrete class to implement your MyQueue interface. In this class add methods to set and get size of the Queue. Class must also set the default size and maximum size of the Queue. It must also control the flow of the Queue by giving messaging such as \"Queue is empty\" or \"Queue is underflow\", \"Queue is overflow\" or \"Full\", when user is trying to Add/insert more item in the Queue when it is already full.
3) Write a test program to use your concrete class. To test your class set your Queue maximum size to 10. Ask from the user to enter Student Name and then store in the Queue. Your main program must offer the following options to the user;
1) Set Maximum size of the Queue (it must show the Queue maximum limit)
2) Add/Insert (Add student name to the Queue)
3) Delete (Take out student name from the Queue)
4) DeleteAll (Delete and Display all student names in the Queue, after this Queue will be empty)
Note: You may add new methods if necessary to fulfill the above mentioned user requirments.
I need a java program, a JAVA PROGRAM. please
1.
package assignment;
// interface for push and pop operations for stack
public interface MyStack {
void push(int element);
void pop();
}
******************************************************************
public class StackUsingArray implements MyStack {
private static final int MaxSize = 10;
int arr[] = new int[MaxSize];
int top = -1;
// method to dispay all elements in stack
public void popUpAll() {
if (top >= 0) {
System.out.println(\"Elements in stack :\");
for (int i = 0; i <= top; i++) {
System.out.println(arr[i]);
}
arr = null;
}
}
// method to push elements in to the stack
@Override
public void push(int pushedElement) {
if (top < MaxSize - 1) {
top++;
arr[top] = pushedElement;
System.out.println(\"Element \"+pushedElement+\" is pushed to Stack !\");
} else {
System.out.println(\"Stack is Overflow !\");
}
}
// method to pop elements from the stack
@Override
public void pop() {
if (top >= 0) {
top--;
System.out.println(\"Pop operation done !\");
} else {
System.out.println(\"Stack is Underflow !\");
}
if(top == -1){
System.out.println(\"Stack is Empty!\");
}
}
public static void main(String args[]){
StackUsingArray stack = new StackUsingArray();
stack.push(123);
stack.push(454);
stack.push(565);
stack.push(675);
stack.pop();
stack.popUpAll();
}
}
2.
package assignment;
//interface for insert and delete operations in the Queue
public interface MyQueue {
void insert(int element);
void delete();
}
package assignment;
public class QueueUsingArray implements Queue {
private static final int capacity = 10;
int arr[] = new int[capacity];
int size = 0;
int top = -1;
int rear = 0;
// method to insert element to the Queue
@Override
public void insert(int element) {
if (top < capacity - 1) {
top++;
arr[top] = element;
System.out.println(\"Element \" + element
+ \" is inserted to Queue !\");
} else {
System.out.println(\"Queue isOverflow !\");
}
}
// method to delete element from the Queue
@Override
public void delete() {
if (top >= rear) {
rear++;
System.out.println(\"Delete operation done!\");
display();
} else {
System.out.println(\"Queue is Underflow !\");
}
}
// method to display al the elements in the Queue
public void display() {
if (top >= rear) {
System.out.println(\"Elements in Queue : \");
for (int i = rear; i <= top; i++) {
System.out.println(arr[i]);
}
arr = null;
}
if(arr == null){
System.out.println(\"Queue is Empty !\");
}
}
public static void main(String[] args) {
QueueUsingArray queueDemo = new QueueUsingArray ();
queueDemo.delete();
queueDemo.insert(23);
queueDemo.insert(2);
queueDemo.insert(73);
queueDemo.insert(21);
queueDemo.display();
}
}