Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I got my program to do exactly what I want it to do, but it does not match the format below. Can someone correct

So I got my program to do exactly what I want it to do, but it does not match the format below. Can someone correct my format?

image text in transcribed

import java.util.*;

public class StackList{

private static final String Stack = null;

static Scanner scan = new Scanner(System.in);

static void showpush(Stack st, int a) {

st.push(new Integer(a));

System.out.println("push(" + a + ")");

System.out.println("stack: " + st);

}

static void showpop(Stack st) {

System.out.print("pop -> ");

Integer a = (Integer) st.pop();

System.out.println(a);

System.out.println("stack: " + st);

}

public static void main(String args[]) {

Stack st = new Stack();

System.out.println("stack: " + st);

try {

showpop(st);

}catch (EmptyStackException e) {

System.out.println("empty stack");

int num = 0;

int s=0;

// loop to for the print shape

while (Stack == null) {

Random generator = new Random();

int ran_dom;

ran_dom = generator.nextInt(20);

System.out.println("Menu: ");

System.out.println("1: add(x) " + " " + "2: del(x)");

System.out.println("3: exist(x)" + " " + "4: Goodbye ");

System.out.print("Please select an options: " );

s = scan.nextInt();

// Allow me to select one of the 3 shapes

switch (s)

{

case 1:

System.out.print("Enter a number: ");

num = scan.nextInt();

System.out.println("You Enter: " + num);

showpush(st, num);

break;

case 2:

System.out.print("Enter a number: ");

num = scan.nextInt();

if (st.contains(num))

{

st.remove(Integer.valueOf(num));

System.out.println(st);

}

else

{

System.out.println("Error:");

}

break;

case 3:

System.out.print("Enter a number: ");

num = scan.nextInt();

if (st.contains(num)) {

System.out.println("Number Exists");

} else {

System.out.println("Number do not Exists");

}

break;

// Allow me to end the program

default:

System.out.print("Goodbye");

// System.exit(0);

}

}}}}

For this assignment, you are to write a program which implements a Set data structure using a singly linked list implementation and a driver program that will test this implementation. The Set ADT is a linear collection of data that will support the following operations: add(x)-adds the integer x to the collection. The resulting collection should not contain any duplicate values 1. 2. delete(x)- deletes the integer x from the set. 3. exists(x) returns true if the integer x exists in the set and false otherwise. 4. toString() - returns a string representing the set as a space separated list. The time complexity of all operations should be O(N), where N is the size of the collection. Program Design Requirements 1. Your program should consist of 3 classes: LinkedNode, Set, and Test. 2. The Test class is the driver class for your program (should contain only the main method). Inside the main method, you should create a new Set object, then enter an infinite loop in which the user is prompted to enter one of 3 commands: add x del x exists x stands for an actual number (some integer). The add and delete operations should perform the necessary operation (inserting or deleting the given integer) and then display the contents of the set using the toString() method. The exists command should output true or false depending on whether x exists in the set. 3. The Set class should implement the Set ADT by adding the appropriate variables and methods. There should be 1 method for each of the required operations. 4. The LinkedNode class should contain an integer value and a pointer to the next LinkedNode. 5. Make sure to validate all inputs. This means re-prompting the user if he or she entered something invalid

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_2

Step: 3

blur-text-image_3

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

Students also viewed these Databases questions