Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 30.7, Problem 30.7.1CP
Explanation of Solution
Purpose of given code:
Purpose of given code is to print the resultant values of given code using aggregate “Collectors” and “Comparator”.
Explanation:
- The array values of variable “values” are printed with their occurrence...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
import java.util.HashSet;
import java.util.Set;
// Define a class named LinearSearchSet
public class LinearSearchSet {
// Define a method named linearSearch that takes in a Set and an integer target
// as parameters
public static boolean linearSearch(Set<Integer> set, int target) {
// Iterate over all elements in the Set
for () {
// Check if the current value is equal to the target
if () {
// If so, return true
}
}
// If the target was not found, return false
}
// Define the main method
public static void main(String[] args) {
// Create a HashSet of integers and populate integer values
Set<Integer> numbers = new HashSet<>();
// Define the target to search for
numbers.add(3);
numbers.add(6);
numbers.add(2);
numbers.add(9);
numbers.add(11);
// Call the linearSearch method with the set…
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…
Write a deletion method for the AVLTree class that utilizes lazy deletion.There are several techniques you can use, but a simple one is to simplyadd a Boolean field to the Node class that signifies whether or not the nodeis marked for deletion. Your other methods must then take this field intoaccount.
Chapter 30 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Ch. 30.1 - Prob. 30.1.1CPCh. 30.2 - Prob. 30.2.1CPCh. 30.2 - Prob. 30.2.2CPCh. 30.2 - Prob. 30.2.3CPCh. 30.2 - Prob. 30.2.4CPCh. 30.3 - Prob. 30.3.1CPCh. 30.3 - Prob. 30.3.2CPCh. 30.3 - Prob. 30.3.3CPCh. 30.3 - Prob. 30.3.4CPCh. 30.3 - Given an array names in Listing 30.1, write the...
Ch. 30.4 - Prob. 30.4.1CPCh. 30.4 - How do you create a parallel stream?Ch. 30.4 - Prob. 30.4.3CPCh. 30.4 - Prob. 30.4.4CPCh. 30.4 - Prob. 30.4.5CPCh. 30.4 - Write a statement to obtain an array of 1000...Ch. 30.5 - Prob. 30.5.1CPCh. 30.5 - Prob. 30.5.2CPCh. 30.5 - Prob. 30.5.3CPCh. 30.5 - Prob. 30.5.4CPCh. 30.6 - Prob. 30.6.1CPCh. 30.7 - Prob. 30.7.1CPCh. 30.8 - Can the following code be used to replace line 19...Ch. 30.8 - Prob. 30.8.2CPCh. 30.8 - Prob. 30.8.3CPCh. 30.8 - Prob. 30.8.4CPCh. 30.8 - Write the code to obtain a one-dimensional array...Ch. 30 - Prob. 30.1PECh. 30 - Prob. 30.2PECh. 30 - Prob. 30.3PECh. 30 - (Print distinct numbers) Rewrite Programming...Ch. 30 - Prob. 30.5PECh. 30 - Prob. 30.6PECh. 30 - Prob. 30.7PECh. 30 - Prob. 30.8PECh. 30 - Prob. 30.9PECh. 30 - Prob. 30.10PECh. 30 - Prob. 30.11PECh. 30 - (Sum the digits in an integer) Rewrite Programming...Ch. 30 - (Count the letters in a string) Rewrite...Ch. 30 - Prob. 30.14PECh. 30 - (Display words in ascending alphabetical order)...Ch. 30 - Prob. 30.16PECh. 30 - Prob. 30.17PECh. 30 - (Count the occurrences of words in a text file)...Ch. 30 - (Summary information) Suppose the file test.txt...
Knowledge Booster
Similar questions
- 6 - question Given the following method; public static void mystery (Map mapl, Map map2) { Map result = new TreeMap (); for (String s1 : mapl. keySet ()) { if (map2.containsKey (mapl.get (s1))) { result.put (sl, map2.get (mapl.get (sl))); } } System.out.println (result); } What is the result for the following input map1: {bar=1, baz=2, foo=3, mumble=4}, map2: {1=earth, 2=wind, 3=air, 4=fire} a. {earth=bar, wind%=baz, air=foo, fire=mumble} b. {bar=earth, baz=wind, foo=air, mumble=fire} c. {1=1, 2=2, 3=3, 4=4} d. {bar=1, baz=2, foo=3, mumble=4}arrow_forwardFile TesSLL.java contains a driver that allows you to experiment with these methods. Compile and run TestSLL, and play around with it to see how it works. Then add the following methods to the SinglyLinkedList class. For each, add an option to the driver to test it. Do this in incremental steps!! This means, implement and test the methods one at a time.arrow_forwardStarter 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); }}arrow_forward
- Listen Consider the following code snippet: LinkedList words = new LinkedList(); words.addLast("abc"); words.addLast("def"); words.addLast("ghi"); System.out.print(words.removeLast()); System.out.print (words.removeFirst(0); System.out.print(words.removeLast()); What will this code print when it is executed O abcdefghi defghiabc O ghiabcdef O abcghidef Previous Page Next Pagearrow_forward? mapMystery ♡ Language/Type: What is the output of the following code? Map map = new TreeMap(); map.put("K", "Schwarz"); map.put("C", "Lee"); map.put("M", "Sahami"); map.put("M", "Stepp"); map.remove("Stepp"); map.remove("K"); map.put("J", "Cain"); map.remove("C, Lee"); System.out.println(map); output a. O {J-Cain, M=Sahami} b. O {J-Cain, C=Lee, M=Sahami, M=Stepp} c. O {C-Lee, J-Cain, M=Stepp} d. O {C-Lee, J-Cain, M=Stepp, M=Sahami} (order shuffled) Java Map TreeMap collectionsarrow_forwardComplete the following method that uses a loop to removes all strings with length less than four from its parameter words. import java.util.Iterator;import java.util.LinkedList; public class Lists{ public static void removeShort(LinkedList<String> words) { Iterator<String> iter = words.iterator(); /* Your code goes here */ }}arrow_forward
- Implement a LinkedList class that stores integers using dynamic memory and a proper main program to test it. The following member functions need to be properly implemented and tested: 1. Default constructor. 2. Parmetrized Constructor. 3. Sum. 4. Average. 5. InsertAtHead. 6. InsertAtTail. 7. Delete. 8. Pop. 9. Circular. 10. Display. Sample answer is also provided.arrow_forwardJava - Mileage for a Runnerarrow_forwardplease fix code to match "enter patients name in lbs" thank you import java.util.LinkedList;import java.util.Queue;import java.util.Scanner; interface Patient { public String displayBMICategory(double bmi); public String displayInsuranceCategory(double bmi);} public class BMI implements Patient { public static void main(String[] args) { /* * local variable for saving the patient information */ double weight = 0; String birthDate = "", name = ""; int height = 0; Scanner scan = new Scanner(System.in); String cont = ""; Queue<String> patients = new LinkedList<>(); // do while loop for keep running program till user not entered q do { System.out.print("Press Y for continue (Press q for exit!) "); cont = scan.nextLine(); if (cont.equalsIgnoreCase("q")) { System.out.println("Thank you for using BMI calculator"); break;…arrow_forward
- Java Program This assignment requires one project with two classes. Class Employee Class Employee Attributes (all private): id: String lastName: String firstName: String salary: int Executable Class create an array of Employee objects. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in ID # order as shown, but do so using the TreeMap's forEach method and a lambda expressionarrow_forwardYou may find a doubly-linked list implementation below. Our first class is Node which we can make a new node with a given element. Its constructor also includes previous node reference prev and next node reference next. We have another class called DoublyLinkedList which has start_node attribute in its constructor as well as the methods such as: 1. insert_to_empty_list() 2. insert_to_end() 3. insert_at_index() Hints: Make a node object for the new element. Check if the index >= 0.If index is 0, make new node as head; else, make a temp node and iterate to the node previous to the index.If the previous node is not null, adjust the prev and next references. Print a message when the previous node is null. 4. delete_at_start() 5. delete_at_end() . 6. display() the task is to implement these 3 methods: insert_at_index(), delete_at_end(), display(). hint on how to start thee code # Initialize the Node class Node: def __init__(self, data): self.item = data…arrow_forwardExplain code and complete. //the third and final class which implements Hashmapspublic class OurMapUse { public static void main(String[] args) { Map<String, Integer> map = new Map<>(); for(int i=0;i<20;i++) { map.insert("abc"+i+1+i); System.out.print("i = "+i+"lf = "+map.loadFactor()); } } }.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education