public class Solution { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); TreeSet t = new TreeSet(); for (int i = 0; i < n; i++) { int value; int command = sc.nextInt(); %3D if (command == 1) { value = sc.nextInt(); t.add (value); } else if (command == 2) { value = sc.nextInt(); t.remove(value); } else if (command == 3) { System.out.println(t.first()); } } }
Q: Write a Java public static general method that doesn't belong to the Queue class(assuming the Queue…
A: package Queue; public class Test { public static void main(String[] args) {…
Q: Need help solving this issue. ShoppingList Class import java.util.Scanner; import…
A: There are some modifications required in the ShoppingList class. The changes are shown below:
Q: Solution in Java Implement a method removeWord() that takes two string parameters: sentence the…
A: In this problem, we need to design the code in the java programming language. Input - two strings…
Q: For any element in keysList with a value greater than 40, print the corresponding value in…
A: import java.util.Scanner;public class LongestLine {public static void main(String args[]) {final int…
Q: make this code runable Int main(void) //Input array containing edges of the graph //(X,Y,W)tuple…
A: There is not clear definition of any function or the block so it is difficult to find the logical…
Q: Write a client program that loops around getting two fractions from the user,output their sum, and…
A: Program code: Fraction.java //Define the class Fractionpublic class Fraction { // declaring instance…
Q: public class Polygon { private double sideLength; private int sides; private String shape; public…
A: A function to call from a static context in java should be static in nature.
Q: 1. Write a generic method selectionSort.
A: Hello student Greetings Hope you are doing great As per our policy guidelines, in case of multiple…
Q: Define a class named FCFSQueue with two private attributes: CustomerList: an array of 100 elements…
A: // C++ program to create and implement FCFS Queue of customers#include <iostream>#include…
Q: Solution in Java Implement a method removeWord() that takes two string parameters: sentence the…
A: As per the requirement program is developed. Algorithm: Step 1: Write the main method Step 2: call…
Q: JAVA: Fill in the ParsedRequest method in the CustomParser.java file. The point of it is to parse…
A: ANSWER: Java Programming: One of the most generally utilized programming dialects, Java is utilized…
Q: Write a method that resizes an array based queue to be exactly the size of the data it contains.…
A: Program Explanation: Import the exception class Define a class for queue Declare the attributes for…
Q: Hi, help me with this problem, please. Also, please follow the skeleton code provided to find the…
A: Actually, given information is: package graph; public class PrimNode implements…
Q: public class elements { public static void main(String args[]) { Scanner sc = new…
A: A flowchart is nothing but the pictorial representation of the sequence of steps in a program. It…
Q: // interface method ================================================== public Node get(int val) {…
A: Given data, public class BSTImpl implements BST { private Node root; private int size;…
Q: Write an efficient java method that computes and returns the height from node t in a btree of any…
A: The algorithm is to find the height of a node t is shown below. height(t) If the t is empty then…
Q: Language: Java Implement a generic method called count() to count the number of elements in a list…
A: PROGRAMMING APPROACH: import a package to get the standard input-output. define a class. define a…
Q: import java.util.ArrayList; public interface PermuteAL { /** * Creates a sequence of numbers. *…
A: Implement this method in the Java language
Q: import java.util.*; // for Arrays class public class ReferenceMystery2 { public static void…
A: Here i written Output with better comments In Java. I hope you like it.
Q: Write a recursive instance method named findBad that takes no parameters and returns a reference to…
A: In programming terms, a recursive function can be defined as a routine that calls itself directly or…
Q: package edu.luc.cs.cs271.mazesolver; import java.util.ArrayList; import java.util.Scanner; public…
A: File: maze.py Project 7.9 Determine the solution to a maze problem. Uses a gid to represent…
Q: Write a Polynomial class that has methods for creating a polynomial, reading and writing a…
A: Given:
Q: in java code: Simulate a forest fire. Complete the ForestFireSimulation class by implementing the…
A: Note: I have run the loop of the main program 10 times for the sake of output printing. As you have…
Q: import java.util.Set; import java.util.TreeSet; import java.util.HashSet; import java.util.Map;…
A: Basically, a map is used to store a person’s name as the key and one’s score as the value. A set of…
Q: Design a method random_key() that returns a random key from BST in time proportional to the tree…
A: The Full form of BST is Binary Search Tree.
Q: Consider class IntArrayStack that has two instance variables: int[] data and int top. Implement an…
A: As per our policy the programming language is not mentioned so i am providing the solution in Java.…
Q: Computer Science 1. Write a generic method named array_prod() that takes an array of a generic type…
A: Code: import java.util.*;public class Demo { public static <T extends Number> double…
Q: In java, Define a new class named BSTWithHeight that extend BST with the following method: /**…
A: class Test{ classNode { intdata; Nodeleft, right; publicNode(intitem) { data = item; left = right =…
Q: class Solution { public: int i++) { { firstUniqChar(string s) { unordered_map m; for (int i=0;…
A: The program for the above given question is given below:
Q: Write the output produced when the following method is passed each of the following maps: public…
A: Actually, given code is: public static void mystery(Map<String, String> m) { Set<String>…
Q: ter Science JAVA!!!!!!!! Use the class MyArrayList to implement the interface MyList listed below…
A: It is defined as a high level, robust, object-oriented and secure programming language. It has the…
Q: Add unit testing to the textanalyzer class. Please perform this task using JUnit. import…
A: JUnit is an open source Java unit testing framework developed by Kent Beck and Erich Gamma. This is…
Q: Line: 2 3 4 + + Result: 9 Line: 12 6 / 4 * 4 + Result: 12 Line: 2 2 3 3 * ** Result: 36 Line: 7 5 /…
A: I give the code along with output and code screenshot in Java
Q: Purpose To review threads in Java. Threading Divisors Directions and Example: A divisor is a number…
A: According to the information given:- we have to follow the instruction mentioned and modify the code…
Q: Type the program's output ColorSorter.java Color.java import java.util.Scanner; import…
A: The solution to the given problem is below.
Q: // This main method provides code to run tests on the play() method. // You are free to add…
A: import java.util.LinkedList;import java.util.ListIterator; public class WordGamePlay { public…
Q: Suppose you are writing a method delete() for a BST class. Describe (either in English or in code)…
A: To delete the given node from the binary search tree(BST), we should follow the below rules: 1.The…
Q: Solution in Java Implement a method removeWord() that takes two string parameters: sentence - the…
A: Input - Array of String Output - missing letter logic - return s.replace(" " + w, ""); In this…
Q: b. import java.util.ArrayList; public class Main { public static void main (String[]args) {…
A: - We have to talk for the ArrayList and get the output of the program. - In the program, we have…
Q: JAVA plese Implement the indexOf method in the LinkedIntegerList class public int indexOf(int…
A: the correct solution is attached below:-
Q: Java programming language I have to create a remove method that removes the element at an index…
A: public class ourArrayList < T > { private Node < T > Head = null; private Node…
Q: Here is my code in Java: import java.util.Scanner; import java.util.HashMap; public class…
A: Your code had some mistakes due to which it was going into an infinite loop which resolved. Now this…
Q: In java program Provide a static method that checks whether a generic array list is a palindrome;…
A: The complete code is given below with the output .
Q: please check my JAVA code. One of my test cases is wrong. The question is as stated in the image…
A: One of your test cases didn't execute because the given code is not checking the case where the…
Q: Implement the following classes in java code, use one of the sorting algorithms mentioned above to…
A: Given classes are: Library Items Book Magazine To use one of the sorting algorithms to implement…
Q: public class Polygon { private double sideLength; private int sides; private String shape; public…
A: Here is Your Code public static int find(Polygon[] list){ int count=0; for(Polygon l :list){…
Q: NameSorter.java Name.java import java.util.Scanner; import java.util.ArrayList; import…
A: code: import java.util.*;public class Main{ public static void main(String[] args) { Scanner scnr =…
Q: package circularlinkedlist; import java.util.Iterator; public class CircularLinkedList implements…
A: Java is a programming language and a platform. Java is a high level, robust, object-oriented and…
Q: All the methods as well as the main method/tester statements must be written in one class. DO NOT…
A: I have answered this question in step 2.
Please explain the code for me.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- import java.util.Scanner; public class ContactList { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ContactNode head = null; ContactNode current = null; // Read the name and phone number for three contacts and build a linked list. for (int i = 1; i <= 3; i++) { System.out.print(" " + i + ": "); String name = scnr.next(); System.out.print(" " + i + ": "); String phoneNumber = scnr.next(); ContactNode newContact = new ContactNode(name, phoneNumber); if (head == null) { head = newContact; current = head; } else { current.insertAfter(newContact); current = newContact; } } // Output each contact. current = head; for (int i = 1; current != null; i++) { System.out.print("Person " + i + ": "); current.printContactNode();…Computer Science JAVA!!!!!!!! Use the class MyArrayList to implement the interface MyList listed below using parallel streams and write a test program to test the methods. The class should be thread safe. interface MyList{ public void add(E x); public void add(List lst); public boolean forAll(Predicate pr); public boolean exists(Predicate pr); public long count(Predicate pr); public List map(Function fn); public List filter(Predicate pr); public List mapFilter(Function fn, Predicate pr); } class MyArrayList implements MyList{ private ArrayList data = new ArrayList<>(); … }Add unit testing to the textanalyzer class. Please perform this task using JUnit. import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.io.*; public class TextAnalyzer { public static void main(String[] args) throws Exception { String Word; URL poem = new URL("https://www.gutenberg.org/files/1065/1065-h/1065-h.htm"); BufferedReader in = new BufferedReader( new InputStreamReader(poem.openStream())); Map map = new HashMap(); while ((Word = in.readLine()) != null) { String[] words = Word.split("[\\s.;,?:!()\"]+"); for (String word : words) { word = word.trim(); if (word.length() > 0) { if (map.containsKey(word)) { map.put(word, map.get(word) + 1); } else { map.put(word, (int) 1L); } } } } // retrieving the map contents Set> set = map.entrySet(); // make an array list List> sortedList = new…
- I need help with my Optimizing the intermediate code to improve the efficiency of the generated machine code. I need to improve the effixiency of the generated machine code import java.util.*; public class SimpleCalculator { private final String input; private int position; private boolean hasDivByZero = false; private Map<String, String> symbolTable; private List<String> instructions; public SimpleCalculator(String input) { this.input = input; this.position = 0; this.symbolTable = new HashMap<>(); this.instructions = new ArrayList<>(); } public static void main(String[] args) { SimpleCalculator calculator = new SimpleCalculator("3 + 5 * (2 - 1)"); calculator.parseExpression(); if (calculator.hasDivByZero) { System.out.println("Error: division by zero"); } else { System.out.println("Result: " + calculator.instructions); } } public void parseExpression() { String t1 = parseTerm(); while (true) { String op = null; if (consume('+')) { op = "+"; } else if…JAVA Implement the equals method of the Arrow class. Two arrows are equal when they have the same starting point and direction. public class Arrow{ private Point start; private String direction; /** Constructs an arrow. @param x the x-position @param y the y-position @param direction a compass direction N E S W NE NW SE SW */ public Arrow(int x, int y, String direction) { start = new Point(); start.move(x, y); this.direction = direction; } /** Checks whether this arrow is equal to another. @param otherObject another arrow @return true if this arrow and otherObject have the same position and direction. */ public boolean equals(Object otherObject) { /* code goes here */ }}import java.util.Scanner;import java.util.ArrayList;import java.util.StringTokenizer; public class PlantArrayListExample { // TODO: Define a printArrayList method that prints an ArrayList of plant (or flower) objects public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String input; // TODO: Declare an ArrayList called myGarden that can hold object of type plant // TODO: Declare variables - plantName, plantCost, flowerName, flowerCost, colorOfFlowers, isAnnual input = scnr.next(); while(!input.equals("-1")){ // TODO: Check if input is a plant or flower // Store as a plant object or flower object // Add to the ArrayList myGarden input = scnr.next(); } // TODO: Call the method printArrayList to print myGarden }}
- For any element in keysList with a value greater than 40, print the corresponding value in itemsList, followed by a semicolon (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20;30; import java.util.Scanner; public class Compare { public static void main(String args[]) {final int SIZE_LIST = 4;int[] keysList = new int[SIZE_LIST];int[] itemsList = new int[SIZE_LIST];int i;Scanner input = new Scanner(System.in); keysList[0] = input.nextInt();keysList[1] = input.nextInt();keysList[2] = input.nextInt();keysList[3] = input.nextInt(); itemsList[0] = input.nextInt();itemsList[1] = input.nextInt();itemsList[2] = input.nextInt();itemsList[3] = input.nextInt(); /* Your code goes here */ System.out.println();} }Computer Science Write a program in the Java language that includes: 1. A class for books, taking into account the encapsulation and getter, setter. 2. Entering books by the user using Scanner 3. LinkedList class for: (Adding a new book - Inserting a book- Searching for a book using the ISBN Number - Viewing all books,delete book). 4. Serial number increases automatically with each book that is entered. 5. Printing the names of books is as follows: Serial - ISBN - Name - PubYear - Price - Notes. 6-Design a main menu that includes: • Add Book • Insert Book • Delete Book • Search . Display . ExitJAVA PROGRAMMING I need an expert to write Test application to run the MyArrayStack<T> class. import java.util.Arrays; interface MyStack<T> {public void push(T o);public T pop() throws StackEmptyException;public T peek();public boolean isEmpty();public int size();} class MyArrayStack<T> implements MyStack<T>{private static final int DEFAULT_STACK_SIZE = 100;T[] stackArray;int top = 0; public MyArrayStack() {this(DEFAULT_STACK_SIZE);}public MyArrayStack(int defaultSize) {top = 0;stackArray = (T[])new Object[defaultSize];} public void push(T o) {if (size() == stackArray.length) expandCapacity();stackArray[top] = o;top++;}private void expandCapacity() {stackArray = Arrays.copyOf(stackArray, stackArray.length*2);System.out.println("StackArray size is automatically expanded:" + stackArray.length);} public T pop() throws StackEmptyException {if (isEmpty()) throw new StackEmptyException("Stack is empty");top--;T o = stackArray[top];stackArray[top] = null;return o;}…
- JAva Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is locatedat a point with integer coordinates and faces north, south, east, or west. Supply methods:public void turnLeft()public void turnRight()public void move()public Point getLocation()public String getDirection()The turnLeft and turnRight methods change the direction but not the location. The move method movesthe robot by one unit in the direction it is facing. The getDirection method returns a string “N”, “S”,“E”, “W”. For the new object, the initial location and facing should be specified. For the initial facing, 0means north, 1 means east, 2 means south, and 3 means west.A tester class, RobotTester, has been provided as follows to help you how to implement the Robot class.Therefore, implement the Robot class such that the following RobotTester class can be executed withoutany changes.import java.awt.Point;/**A class to test the Robot class.*/public class RobotTester{/**Tests the…For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, mport java.util.Scanner; public class Compare { public static void main(String args[]) {final int SIZE_LIST = 4;int[] keysList = new int[SIZE_LIST];int[] itemsList = new int[SIZE_LIST];int i;Scanner input = new Scanner(System.in); keysList[0] = input.nextInt();keysList[1] = input.nextInt();keysList[2] = input.nextInt();keysList[3] = input.nextInt(); itemsList[0] = input.nextInt();itemsList[1] = input.nextInt();itemsList[2] = input.nextInt();itemsList[3] = input.nextInt(); /* Your code goes here */ System.out.println();} }package sorting; import java.util.Arrays; import java.util.Random; import sorting.Heap; public class ComparisonSorter { public static void insertionSort(int[] arr) { for(int i=1;i<arr.length;i++) { int j = i-1; int toPlace = arr[i]; while(j>=0&&arr[j]>toPlace) { arr[j+1] = arr[j]; j--; } arr[j+1] = toPlace; } } public static void mergeSort(int [] arr) { mergeSortRecurse(arr,0,arr.length-1); } private static void mergeSortRecurse(int[] arr, int start, int end) { if(start>=end) return; int mid = start + ((end-start)/2); mergeSortRecurse(arr,start,mid); mergeSortRecurse(arr,mid+1,end); merge(arr,start,mid,end); } private static void merge(int[] arr, int start, int mid, int end) { int leftSize = mid - start +1; int rightSize = end - mid; int[] left = new int[leftSize+1]; int[] right = new int[rightSize+1]; int leftIndex; int rightIndex; for(leftIndex = 0; leftIndex<leftSize;leftIndex++) left[leftIndex] = arr[start+leftIndex]; for(rightIndex = 0;…