Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 30.5, Problem 30.5.4CP
Explanation of Solution
Purpose of given code:
The purpose of given code is to print resultant elements in array variable “m” with “IntStream” class using aggregate functions. It prints all distinct values using “distinct()” method and prints all resultant values of array “m[][]” using “forEach()” method with a character “,”...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a Program in C Language.
void doo(list &L){
int item,a,p=L.size()-1; L.retrieve(p,a);
for(int i=0;i
A map is a container object that stores a collection of key/value pairs. It enables fast retrieval, deletion, and updating of the pair through the key. A map stores the values along with the keys. The keys are like indexes. In List, the indexes are integers. In Map, the keys can be any objects.
A map cannot contain duplicate keys. Each key maps to one value. A key and its corresponding value form an entry stored in a map. There are three types of maps: HashMap, LinkedHashMap, and TreeMap. The common features of these maps are defined in the Map interface.
1.Using the Map interface knowledge, create a Java application in NetBeans that implements a HashMap and a LinkedHashMap. The application must do the following:
a. Add at least 5 elements to the HashMap
b. Print out all the elements in the HashMap including their keys
c.Find and print out the value of a specific indexd. Remove one of the elements from the HashMap
e. Print out the HashMap after removing the element
f. Add at least 5…
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java Program: There are errors in the lexer and shank file. Please fix those errors and there must be no error in any of the code at all. Below is the lexer, shank, and token files. The shank file is the main method. There is a rubric attached as well. Lexer.java import java.util.ArrayList;import java.util.HashMap;import java.util.List; import mypack.Token.TokenType; public class Lexer { private static final int INTEGER_STATE = 1;private static final int DECIMAL_STATE = 2;private static final int IDENTIFIER_STATE = 3;private static final int SYMBOL_STATE = 4;private static final int ERROR_STATE = 5;private static final int STRING_STATE = 6;private static final int CHAR_STATE = 7;private static final int COMMENT_STATE = 8; private static final char EOF = (char) -1; private static String input;private static int index;private static char currentChar;private static int lineNumber = 1;private static int indentLevel = 0;private static int lastIndentLevel = 0; private static…arrow_forwardimport java.util.LinkedList; import java.util.Scanner; import java.util.Arrays; import java.io. File; import java.io.FileNotFoundException; public class Ch6Lab{ public static void main(String[] args) throws FileNotFoundException{ LinkedList numbers = new LinkedList(); Scanner fileIn = new Scanner (new File("input.txt")); while (fileIn.hasNextInt()){ int x = fileIn.nextInt(); numbers.add(x); } public static void sort(Linkedlist 1){ ; //TODO: Write a sort method that sorts the linked list } public static Integer min(LinkedList 1){ return e; //TODO0: Write a method that returns the minimum value from the linked 1ist } public static Integer max(LinkedList 1){ return 0; //TODO: Write a method that returns the maximum value from the linked list public static double mean (LinkedList 1){ return 0.0; //TODO: Write a method that returns the mean of the values from the linked list } public static double median(LinkedList 1){ return 0.0;arrow_forwardint binsearch (int X , int V [] , int n ) { int low , high , mid , i ; low = 0; high = n - 1; for ( i = 0; i < high ; i ++) { if( V[ i ] > V [ i +1]) return -2; } while ( low <= high ) { mid = ( low + high )/2; if ( X < V [ mid ]) high = mid - 1; else if ( X > V [ mid ]) low = mid + 1; else return mid ; } return -1; } This code takes as input a sorted array V of size n, and an integer X, if X exists in the array it will return the index of X, else it will return -1. 1. Draw a CFG for binsearch(). 2. From the CFG, identify a set of entry–exit paths to satisfy the complete statement coverage criterion. 3. Identify additional paths, if necessary, to satisfy the complete branch coverage criterion. 4. For each path identified above, derive their path predicate…arrow_forward
- Write a function called genericSort() that takes in a numeric or integer vector, sorts it, and returns the indices of the sorted values. It should also print an error if the input is a character. For example, genericSort(c(1,3,7,5)) should return the vector (1,2,4,3). Programming in Rarrow_forwardJava Program ASAP Please modify Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); in the program so it reads the two text files and passes the test cases. Down below is a working code. Also dont add any import libraries in the program just modify the rest of the code so it passes the test cases. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class MorseCodeConverter { public static void main(String[] args) { Map<String, String> morseCodeMap = readMorseCodeTable("morse.txt"); Scanner scanner = new Scanner(System.in); System.out.print("Please enter the file name or type QUIT to exit:\n"); do { String fileName = scanner.nextLine().trim(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { String text =…arrow_forwardA map is a container that stores a collection of ordered pairs, each pair consists of a key and a value, <key, value>. Keys must be unique. Values need not be unique, so several keys can map to the same values. The pairs in the map are sorted based on keys. Group of answer choices True Falsearrow_forward
- what is the problem in this code ? def add():id = input("Enter ID:")f = open("data.txt", "r")id_list = []lines = f.readlines()if lines != "":for line in lines:token = line.split(" ")id_list.append(token[0])for i in id_list:if i == id:print("The student record is already in the database!Zero records added")returnf.close()file = open("data.txt", "a")name = input("Enter name: ")course = input("Enter course: ")absences = int(input("Enter absences: "))exam1 = int(input("Enter exam 1 grade: "))exam2 = int(input("Enter exam 2 grade: "))marks = int(input("Enter Total Marks: "))s = id+" "+name+" "+course+" "+str(absences)+" "+str(exam1)+" "+str(exam2)+" "+str(marks)+"\n"file.write(s)file.close()while True:print("1.Add a student")print("Any other numeric to terminate")choice = int(input())if choice == 1:add()else:breakarrow_forwardJava Programming Language code not working due to this reason: Simple.java:17: error: class, interface, or enum expected Check the bold in the code for reference CODES: //Java Program to write integer object to a stream and read this object from a streamimport java.util.*;import java.util.stream.*;class Simple{ private static void getStream() { Stream<Integer>stream=Stream.of(11,12,13,14,15,16,17); stream.forEach(p -> System.out.print(p + " ")); } public static void main(String[] args) { getStream(); }}//Simple Encryption Java Programimport java.util.*;public class SimpleEncryption {public static void main(String args[]){ Scanner sc= new Scanner(System.in); System.out.println("Enter shift size:"); int shift = sc.nextInt(); System.out.println("Message read from the file:"); String plaintext= sc.next(); String ciphertext=""; char alphabet; for(int i=0;i<plaintext.length();i++){ alphabet=plaintext.charAt(i);…arrow_forwardEdit the following: package dao; import com.mongodb.client.MongoCollection; import dto.BasePaymentDto; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import org.bson.Document; import org.bson.types.ObjectId; public class PaymentDao implements BaseDao<BasePaymentDto> { private static PaymentDao instance; public MongoCollection<Document> collection; // TODO instead of using a list, directly use mongo to load/store private PaymentDao(MongoCollection<Document> collection){ this.collection = collection; } public static PaymentDao getInstance() { if (instance == null) { instance = new PaymentDao(MongoConnection.getCollection("Payments")); } return instance; } public static PaymentDao getInstance(MongoCollection<Document> collection) { instance = new PaymentDao(collection); return instance; } @Override public void put(BasePaymentDto basePaymentDto) { } @Override public BasePaymentDto get(String id) { return null; } @Override…arrow_forward
- 3. Write the following code using forEach(). for (let i=0; iarrow_forwardComputer Science Using Java: How can I combine a Lambda Expression with a Stream to output something? For example, if I have: public static final ToLongFunction<Stream<String>> numOfPeople = null; // where numOfPeople recieves a list of Strings from a CSV file, how can I return an integer indicating how many people are in that list? It also has to be in lambda formarrow_forward1. The append() method concatenates the string representation of any other type of data tothe end of the invoking StringBuffer object. It has several overloaded versions. Here are afew of its forms:StringBuffer append(String str)StringBuffer append(int num)StringBuffer append(Object obj)2. The result is appended to the current StringBuffer object.3. The buffer itself is returned by each version of append( ).4. This allows subsequent calls to be chained together, write java code for itarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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