Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Implement following code using linked list instead of stack. Please use only scanner. import java.util.Scanner; class Stack { private int array[]; private int top;

JAVA

Implement following code using linked list instead of stack. Please use only scanner.

import java.util.Scanner;

class Stack { private int array[]; private int top;

Stack() { array = new int[10]; top = -1; }

public void push(int a) { if (top < 10) { array[++top] = a; } else { System.out.println("Sorry we can't process any more orders at the moment."); } }

public void pop() { if (top == -1) { System.out.println("There's no orders to process."); } else { System.out.println("Serving order number: " + array[top]); top--; } }

public void display() { if (top == -1) { System.out.println("There's no orders to show."); } else { int i; System.out.println("The list of orders is: "); for (i = 0; i <= top; i++) { System.out.println(array[i]); } } } }

public class Doughnuts { private static Scanner sc;

public static void main(String args[]) { Stack obj; obj = new Stack(); int ch, orderId; orderId = 1; ch = -1; while (ch != 4) { System.out.println( " Welcome to the doughnut machine 1: Place an order 2: Recieve the order 3: Display order list 4: Exit "); System.out.print(" Please enter your choice: "); sc = new Scanner(System.in); ch = sc.nextInt(); switch (ch) { case 1: { obj.push(orderId++); break; } case 2: { obj.pop(); break; } case 4: { System.out.println("Thank You for using our service!"); break; } case 3: { obj.display(); break; } default: { System.out.println("Please enter a valid choice!"); break; } } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

4. Show the trainees how to do it again.

Answered: 1 week ago