Which of the following can be used to replace YYYYYYYY in the following code? public class WildCardDemo{ public static void main(String[] args) { GenericStack stack1 = new GenericStack<>(); GenericStack stack2 = new GenericStack<>(); stack2.push("Java"); stack2.push(2); stack1.push("Sun"); add(stack1, stack2); } public static void add(GenericStack stack1,GenericStack stack2) { while (!stack1.isEmpty()) stack2.push(stack1.pop()); } Select one: O a. ? extends Object b. ? extends T c. ? super T
Q: Considering the following java code QueueClasss qq = new QueueClas(); StackClasss ss = new…
A: here two data structures are used stack and queue. The first four values are pushed in the…
Q: package DataStructures; import ADTs.StackADT; import Exceptions.EmptyCollectionException; /** * *…
A: Actually, program is an executable software that runs on a computer.
Q: Given the queue myData 12, 24, 36 (front is 12), what is the result of the following operations?…
A: The original queue(myData) is 12, 24, 36 where 12 is front. Thus 36 is rear.
Q: Which of the below lines is not a part of the output of the below code? public static void…
A: Ans: Code: public static void main(String[] args) { Stack<Integer> a = new…
Q: In java, how can I print a linkedlist of type people in order by writing a loop that will get the…
A: We need to write a method that print the ith value of the linked list of the type people.
Q: Write a method called removeBelow in the class StackApplication that accepts two parameters called…
A: NOTE Below is the answer for the given question. Hope you understand it well. If you have any…
Q: Write a doctest case that tests whether a StackTypeError is thrown when a TypedStack raises an…
A: The doctest module searches for items of text that appear as if interactive Python sessions, then…
Q: Distinguish between the Java classes GenericServlet and HttpServlet using an example.
A:
Q: What would be the output of the following program: public class StackTest { public static void…
A: Content for First Stack 4, 6, 8,10
Q: in java, Write a method void popMult(int k) for the LinkedStack class which will pop k items from…
A: Write a method void popMult(int k) for the LinkedStack class which will pop k items from this. Throw…
Q: Given the following code, using our HashTable implementation: HashTable table = new HashTable (5);…
A: Actually, given question regarding hashTable implementation.
Q: what is the correct formula for the load factor?
A: The load factor is the proportion of the array's size to the number of entries in the hash table.…
Q: A chained hash table has an array size of 512; what is the maximum number of entries that can be…
A: Introduction: Hashing is one of the technology to transfer any value to different values in the key,…
Q: In Java, how does HashMap manage collisions?
A: GIVEN: In Java, how does HashMap manage collisions?
Q: Given the following LinkedList named list: head 12 5 20 What is the output of the following code?…
A:
Q: With the help of an example, distinguish between the Java classes GenericServlet and HttpServlet.
A: Introduction: In this answer, I will show you how to tell the javas Generic Servlet from the HTTP…
Q: Simple examples for each javas GenericServlet and HttpServlet with your own words.
A: GenericServlet class provides the implementation of all the methods of these interfaces except the…
Q: What is the sum of all the removed values in the following sequence of operations using generic push…
A: The answer is:24. Explanation below:
Q: Implement a Queue class whose add and remove methods are synchronized. Supply one thread, called the…
A: Answer : import java.util.concurrent.locks.Condition;import…
Q: Write a method called deleteAll() that takes a linked list of integers along an integer which…
A: public void deleteAll(int key) { // Store head node Node temp = head;…
Q: Write the output produced when the following method is passed the following stack: bottom: [42 -3 4…
A: bottom: [42 -3 4 15 9] :top public static vod mstery1(Stacj<Integer>s) { Queue<Integer>…
Q: Group of answer choices A. list_t is already thread-safe and does not need any locks in any of its…
A: B. Add a lock to the list_t struct, initialize the lock in the List_Init, and then any operation…
Q: Given an empty stack menultems, what will be the result of the following operations? menuItems.…
A: A Stack is a linear data structure that follows the LIFO(Last In First Out) order. It has one end…
Q: Which of the following is designed to give efficient access to data in secondary storage such as a…
A: A heap structure developed for secondary storage is suggested that tries to make the best use of the…
Q: java, Write a method for the LinkedStack class that will compare two LinkedStacks. Return true if…
A: It is defined as an object oriented and a high level programming language. Every java program is a…
Q: reate a class called RemoveDuplicates that takes a LinkedList of colors (represented using Strings)…
A: Use a variable called duplicateCount and set it when removeDuplicates is called
Q: Consider the following Java Code: What is the output when this code is executed? import…
A: Here is Your Code import java.util.LinkedList; import java.util.ListIterator; class Main{ public…
Q: Which 3 classes from the Java Collections Framework implement Stack operations? Stack, LinkedList,…
A: Stack operations are:- 1. Push 2. Pop
Q: Imagine you are writing the code to manage a hash table
A: Answer) We are writing a code for mutual exclusion for a hash table which will be shared among…
Q: Which of the following data structure works on the "LIFO" principle? A Stacks. B Queues. Deque. D…
A: Please find the answer below :
Q: how to answer the following questions Given that values is of type LLNode and references a linked…
A: In the given code we are passing the list of integer type objects which has nothing means it is…
Q: Using the generic stack psuedocode below, what was the last value popped? Push 9 Pop x Push 7 Push…
A:
Q: Write a method “rotate” that takes a java LinkedList of integers as a parameter and an integer…
A: Language is one of the most widely used programming language which has been used to create different…
Q: Write a code in Python to join two linked-list-based stacks of books into one stack based on the…
A: The code is
Q: Implement generic class ArrayStack as discussed in the lectures having following methods:
A: Stack.java will be the interface for the respective problem, package stack; public interface Stack…
Q: A LinkedList implementation is given below. Complete the program as per comments. import [1] / which…
A: import java.util.*; public class MyLinkedListApp { public static void main(String args[])…
Q: ADTStack myStack = new StackUsingArrays(); for(int i=5; i>0; i--) myStack.push(i);…
A: here stack is defined using class StackUsingArrays when push operation takes place, it push 5 then…
Q: Write a non-generic method findAndRemoveLargest (StackClass myStack) that finds and removes the…
A: output should be -373 if my stack is empty.
Q: in java please Write a main method that adds the numbers from 1 to 10 to a LinkedList. The…
A: logic: create an integer linked list and use loop to store number from 1 to 10. create an Iterator…
Q: How to answer the following questions screenshot shows the ArrayBoundedStack class and…
A: The following expression is balanced: ( ( ( [ ) ] ) ) True or False ANS: - True To check if the…
Q: Write a method called removeBelow in the class StackApplication that accepts two parameters called…
A: As no language has been specified, here C++ has been used to design the code.
Q: 2. Differentiate the javas GenericServlet and HttpServlet with example?
A: 2. Differentiate the javas GenericServlet and HttpServlet with example?
Q: Which statement about Hashtable is false? Hashtable implements Collection. Hashtable is thread safe.…
A: In a 64-bit system, a char occupies 1 byte space.
Q: Which 3 classes from the Java Collections Framework implement Stack operations? O Stack, LinkedList,…
A: Option 1: Stack, LinkedList, ArrayList
Q: A class named DownloadURL has the readAl1 (URL urls(]) method, the method accepts an array of URLS…
A: // import libraries import java.io.*; import java.net.*; import java.util.*; public class…
Q: Write a method called removeBelow in the class StackApplication that accepts two parameters called…
A: import java.util.*;import java.util.Arrays;class StackApplication { void removeBelow(int a,int…
Q: Assignment2: Analyse the case study given in chapter 4 stack Answer the following questions from the…
A: Different methods are:-
Q: We know that java generics cannot prevent runtime error. Then, how can we avoid runtime error while…
A: Java generics allows to create a single class, interface and method that can be used with different…
Q: If a stack is implemented as a linked list, which XXX would replace the missing statement?…
A: A stack implemented using linked list works for the variable size of data. It will store the…
help
Step by step
Solved in 2 steps
- public interface StackInterface void push (T element) throws StackoverfloWException; void pop () throws StackUnderflowException; T top () throws StackUnderflowException; boolean isFul1 (); boolean isEmpty(); Show what is written by the following segments of code (see printın on the code), given that iteml, item2, and item3 are int variables, and ali is an object that fits the abstract description of a stack as shown above StackInterface. Assume that you can store and retrieve variables of type int on ali. iteml = 2; item2 = 0; item3 = 6; ali.push (item2); ali.push (item1); ali.push ( iteml+item3); item2 = ali.top ( ); ali.push (item3*item3); ali.push (item2); ali.push (3); iteml = ali.top ( ); ali.pop( ); System.out.println (iteml + " " + item2 + while (!ali.isEmpty( )) + item3); iteml = ali.top( ) ; ali.pop () ; System.out.println (item1) ;import java.util.ArrayList; public class Bus { privateStringname; privateintsize; privateintbasePrice; privateArrayList<Trip>approvedTrips; privateintlevel;// 1,2,3 for low,medium, high repectively; privateintid; privatestaticintnextId=0; privateMinistrymny; protectedStringtripTypes; privateintgetNextId(){ returnnextId++; } publicBus(){ approvedTrips=newArrayList<Trip>(); } publicBus(Stringname,intsize,intbasePrice,intlev,Ministrymny){ approvedTrips=newArrayList<Trip>(); this.name=name; this.size=size; this.basePrice=basePrice; this.level=lev; this.id=getNextId(); this.mny=mny; tripTypes="BASICTRANSPORT"; } publicbooleanavailable(Datedate){ booleanretval=true; for(Tript:approvedTrips) if(t.getDate().getDay()==date.getDay()) retval=false; returnretval; } publicintgetBasePrice(){ returnbasePrice; } publicintgetId(){ returnid; } publicStringgetName(){ returnname; } publicdoublegetSize(){ returnsize; } publicStringtoString(){ returnname; }…2. By using the above class definition, write a program statement for each of the operation: // Import the LinkedList class import java.util.LinkedList; public class linkedListl { public static void main(String[] args) { LinkedList cars = new LinkedList (); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); } } a) Use removeFirst () remove the first item from the list b) Use removeLast () remove the last item from the list c) Use getFirst () to display the first item in the list d) Use getLast () to display the last item in the list
- In Java import java.util.Scanner; public class ShoppingList { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); ItemNode headNode; // Create intNode objects ItemNode currNode; ItemNode lastNode; String item; int i; // Front of nodes list headNode = new ItemNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ){ item = scnr.next(); currNode = new ItemNode(item); lastNode.insertAtEnd(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode = currNode.getNext(); } } } ----------------------------------------- public class ItemNode { private String item; private ItemNode nextNodeRef; // Reference to the next node public ItemNode() { item = ""; nextNodeRef = null; } // Constructor public ItemNode(String itemInit) { this.item = itemInit; this.nextNodeRef = null; } // Constructor public…import java.util.Scanner; public class ShoppingList { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); ItemNode headNode; // Create intNode objects ItemNode currNode; ItemNode lastNode; String item; int i; // Front of nodes list headNode = new ItemNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ){ item = scnr.next(); currNode = new ItemNode(item); lastNode.insertAtEnd(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode = currNode.getNext(); } }}public class CustomLinkedList { public static int findMax(IntNode headObj) { /* Type your code here */ } public static void main(String[] args) { IntNode headObj; IntNode currObj; IntNode lastObj; int i; int max; // Create head node headObj = new IntNode(-1); lastObj = headObj; // Add nodes to the list for (i = 0; i < 20; ++i) { currObj = new IntNode(i); lastObj.insertAfter(currObj); lastObj = currObj; } max = findMax(headObj); System.out.println(max); }}
- public class ShoppingListDriver{ public static void main(String[] args){ ShoppingList sl=new ShoppingList(3);sl.insert(null);sl.insert(new Item("Bread", "Carb Food", 2, 2.99));sl.insert(new Item("Seafood","Sea Food", -1, 10.99));sl.insert(new Item("Rice", "Carb Food",2, 19.99));sl.insert(new Item("Salad Dressings","Dessing", 2, 19.99));sl.insert(new Item("Eggs", "Protein",2, 3.99));sl.insert(new Item("Cheese","Protein", 2, 1.59));sl.insert(new Item("Eggs", "Protein",3, 3.99));sl.printNames();sl.print(); System.out.println("After removing Eggs:");sl.remove(new Item("Eggs","Protein",0,0));sl.printNames();sl.print(); }}API documentation link ------> https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ArrayList.html PREVIOUS CODE - import java.util.ArrayList;public class BasicArrayList { // main method public static void main(String[] args) { // create an arraylist of type Integer ArrayList<Integer> basic = new ArrayList<Integer>(); // using loop add elements for(int i=0;i<4;i++){ basic.add(i+1); } // using loop set elements for(int i=0;i<basic.size();i++){ basic.set(i,(basic.get(i)*5)); } // using loop print elements for(int i=0;i<basic.size();i++){ System.out.println(basic.get(i)); } }} Q1) a)Consider how to remove elements from the ArrayList. Give two different lines of code that would both remove 5 from the ArrayList. b)What do you think the contents of the ArrayList will look like after the 5 has been removed? (Sketch or list) c)Now update the BasicArrayList program to remove the 5 (index 1) from the ArrayList. Add this step before the last loop that…class WaterSort { Character top = null; // create constants for colors static Character red= new Character('r'); static Character blue = new Character('b'); static Character yellow= new Character('g'); // Bottles declaration public static void showAll( StackAsMyArrayList bottles[]) { for (int i = 0; i<=4; i++) { System.out.println("Bottle "+ i+ ": " + bottles[i]); } } public static void main(String args[]) { //part 1 //create the bottle StackAsMyArrayList bottleONE = new StackAsMyArrayList<Character>(); System.out.println("\nbottleONE:"+ bottleONE+ " size:" + bottleONE.getStackSize()+" uniform? "+ bottleONE.checkStackUniform());…
- how to create an interface in java that contains the following methods: boolean myPush(T element); // pushes element onto the stack; returns true if element successfully pushed, false otherwise boolean myPop(); // removes the top element of the stack; returns true if element successfully popped, false otherwise T myTop(); // if the stack is not empty returns the top element of the stack, otherwise returns null String toString(); // returns contents of the stack as a single String int size(); // return number of elements in the stack then create java file that Implements your interface that you created as a linked stack, then use the driver shown in screen shot to test. below is the code for the LLNode class public class LLNode<T> { protected LLNode<T> link; protected T info; public LLNode(T info) { this.info = info; link = null; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode<T> link) {…import java.util.Scanner; public class Playlist { // TODO: Write method to ouptut list of songs public static void main (String[] args) { Scanner scnr = new Scanner(System.in); SongNode headNode; SongNode currNode; SongNode lastNode; String songTitle; int songLength; String songArtist; // Front of nodes list headNode = new SongNode(); lastNode = headNode; // Read user input until -1 entered songTitle = scnr.nextLine(); while (!songTitle.equals("-1")) { songLength = scnr.nextInt(); scnr.nextLine(); songArtist = scnr.nextLine(); currNode = new SongNode(songTitle, songLength, songArtist); lastNode.insertAfter(currNode); lastNode = currNode; songTitle = scnr.nextLine(); } // Print linked list…Starter code for ShoppingList.java import java.util.*;import java.util.LinkedList; public class ShoppingList{ public static void main(String[] args) { Scanner scnr=new Scanner(System.in); LinkedList<ListItem>shoppingList=new LinkedList<ListItem>();//declare LinkedList String item; int i=0,n=0;//declare variables item=scnr.nextLine();//get input from user while(item.equals("-1")!=true)//get inputuntil user not enter -1 { shoppingList.add(new ListItem(item));//add into shoppingList LinkedList n++;//increment n item=scnr.nextLine();//get item from user } for(i=0;i<n;i++) { shoppingList.get(i).printNodeData();//call printNodeData()for each object } }} class ListItem{ String item; //constructor ListItem(String item) { this.item=item; } void printNodeData() { System.out.println(item); }}