Question

In Java language: 1. The complement of a queue is a stack. It uses first-in, last-out...

In Java language:

1. The complement of a queue is a stack. It uses first-in, last-out accessing and is often likened to a stack of plates. The first plate put on the table is the last plate used. Create a stack class called Stack that can hold characters. Call the methods that access the stack push( ) and pop( ). Allow the user to specify the size of the stack when it is created. Keep all other members of the Stack class private. (Hint: You can use the Queue class as a model; just change the way the data is accessed.) Add a custom exceptions to your class that report stack full and stack empty conditions.

2. Create a HelloWorld Swing application.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

import java.util.*;

public class Stack
{
static int s;
static int top = 0;

private static void push_element (Stack <Character> stack,char i, int s)
{
if (top < s)
{
   stack.push (i);
   top++;
}
else
System.out.println ("stack is full");

}

private static void pop_element (Stack <Character> stack)
{
if (top >0)
{
   System.out.println (stack.pop ());
   top--;
}
else
System.out.println ("stack is empty");

}

public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter the size of stack");
s = sc.nextInt();
Stack <Character> stack = new Stack <Character> ();
stack.setSize(s);
push_element (stack,'A',s);
push_element (stack,'B',s);
push_element(stack,'C',s);
push_element(stack,'C',s);
pop_element(stack);
pop_element(stack);
pop_element(stack);
pop_element(stack);
}
}

2.

import java.awt.Dimension;
import javax.swing.JFrame;

public class Main {

public static void main(String args[]){
JFrame jf = new JFrame("Hello world");

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(new Dimension(200,200));

jf.setVisible(true);
}
}

Add a comment
Know the answer?
Add Answer to:
In Java language: 1. The complement of a queue is a stack. It uses first-in, last-out...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using java Create a simple queue class and a simple stack class. The queue and stack...

    Using java Create a simple queue class and a simple stack class. The queue and stack should be implemented as a linked list. Create three functions that utilize these data structures Write a function that opens a text file and reads its contents into a stack of characters. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse...

  • In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will co...

    In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will convert strings sent over a serial bus one character at a time. The conversion will be from big to little endian or from little to big endian. To simplify this, each character will be considered a word. Little endian will have the lowest address first. Big endian will have the biggest address first. For example (for this lab),...

  • Use Java to implement a basic stack using an array of integers. For the stack, you...

    Use Java to implement a basic stack using an array of integers. For the stack, you will create an array of integers that holds 5 numbers. To make it easier, you can declare the array at the class level. That way you will be able to use the array in any method in your class without using parameters. Your input/output interface should look something like the following: What operation do you want to do? push What number do you want...

  • help finish Queue, don't think I have the right thing. # 1. After studying the Stack...

    help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...

  • Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your...

    Lab 3 – Array-Based Stack and Queue Overview In this assignment, you will be implementing your own Array-Based Stack (ABS) and Array-Based Queue (ABQ). A stack is a linear data structure which follows the Last-In, First-Out (LIFO) property. LIFO means that the data most recently added is the first data to be removed. (Imagine a stack of books, or a stack of papers on a desk—the first one to be removed is the last one placed on top.) A queue...

  • Please answer question 8.35 Python 3.0 for language Comment for each part of line of code...

    Please answer question 8.35 Python 3.0 for language Comment for each part of line of code explaining what is being done 8.35 A stack is a sequence container type that, like a queue, supports very restrictis methods: All insertions and removals are from one end of the stack, typicly aces the top of the stack. Implement container class Stack that implements cked to a a subclass of object, support the len) overloaded operator, and support the me be referred a...

  • e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return t...

    e. public class Queue { // Uses the correct Stack class from ME2 Ex 19 private Stack mStack; public Queue() { setStack(new Stack()); } public Queue enqueue(E pData) { getStack().push(pData); return this; } public E dequeue() { return getStack().pop(); } public E peek() { return getStack.peek(); } private Stack getStack() { return mStack; } private void setStack(Stack pStack) { mStack = pStack; } } f. public class Queue extends Stack { // Uses the correct Stack class from ME2 Ex...

  • Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The...

    Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...

  • Stacks and Java 1. Using Java design and implement a stack on an array. Implement the...

    Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...

  • java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then...

    java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> {    LinkedList<T> list;       public Stack() {        list = new LinkedList<T>();    }       public boolean isEmpty() {        return list.isEmpty();   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT