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
Expert Solution & Answer
Chapter 20.4, Problem 20.4.1CP
Explanation of Solution
“Yes”, user can use the forEach() method on any instance of collection class.
- forEach() method is the default method in the Iterable interface.
- forEach() method is defined in Collection classes which inherit iterable interface to iterate through the elements.
Program:
import java.util.ArrayList;
import java.util.List;
public class Foreachexample
{
public static void main(String[] args)
{
//Create new Arralist
List<String> l1 = new ArrayList<String>();
//Add elements to the array
l1...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Part 2: Sorting the WorkOrders via dates
Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class.
The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters.
You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you…
Retrieving a value using its associated key can be accomplished using anindexer, which works just like an indexer for an array. A key is passed in asthe index value, and the value associated with the key is returned, unless thekey doesn’t exist, in which a null is returned.Write short code segment demonstrates how this technique works:
The code given below represents a saveTransaction() method which is used to save data to a database from the Java program. Given the classes in the image as well as an image of the screen which will call the function, modify the given code so that it loops through the items again, this time as it loops through you are to insert the data into the salesdetails table, note that the SalesNumber from the AUTO-INCREMENT field from above is to be inserted here with each record being placed into the salesdetails table. Finally, as you loop through the items the product table must be update because as products are sold the onhand field in the products table must be updated. When multiple tables are to be updated with related data, you should wrap it into a DMBS transaction.
The schema for the database is also depicted.
public class PosDAO { private Connection connection; public PosDAO(Connection connection) { this.connection = connection; } public void…
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
Knowledge Booster
Similar questions
- 12. You have written a sorting method that takes an array of Object as its parameter. What limitations are imposed on the users of this method?arrow_forwardYou are required to complete the LinkedList class. This class is used as a linked list that has many methods to perform operations on the linked list. To create a linked list, create an object of this class and use the addFirst or addLast or add(must be completed) to add nodes to this linked list. Your job is to complete the empty methods. For every method you have to complete, you are provided with a header, Do not modify those headers(method name, return type or parameters). You have to complete the body of the method. package chapter02; public class LinkedList { protected LLNode list; public LinkedList() { list = null; } public void addFirst(T info) { LLNode node = new LLNode(info); node.setLink(list); list = node; } public void addLast(T info) { LLNode curr = list; LLNode newNode = new LLNode(info); if(curr == null) { list = newNode; } else { while(curr.getLink() !=…arrow_forwardI already have the code for the assignment below, but the code has an error in the driver class. Please help me fix it. The assignment: Make a recursive method for factoring an integer n. First, find a factor f, then recursively factor n / f. This assignment needs a resource class and a driver class. The resource class and the driver class need to be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code The code of the resource class: import java.util.ArrayList;import java.util.List; public class U10E03R{ // Recursive function to // print factors of a number public static void factors(int n, int i) { // Checking if the number is less than N if (i <= n) { if (n % i == 0) { System.out.print(i + " "); } // Calling the function recursively // for the next number factors(n, i +…arrow_forward
- 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_forwardIn this lab, you will create a backend class called SortableSet. A set, in computer science, is an unordered collection of unique objects. In our SortableSet, all of the objects in the set will also be immutable at the set level. This means that even if the data class used to create objects is not immutable, once they are in the set they are. We do this by making a deep copy of any objects being added to the set or returned from the set. The objects stored in the SortableSet must implement an interface called Sortable that provides a numeric sorting key and a deep copy method. SortableSet also takes advantage of two custom exception classes: DuplicateException and InvalidKeyException. Finally, the "sortable" part of SortableSet is implemented by a getSortedList method that makes a deep copy of every object in the set, saves them to an array, and then sorts them based on each object's sorting key. The sort algorithm used is a recursive radix sort modified to work with objects.arrow_forwardPart 4. sum Method Define a method in simpy named sum. Its purpose is to compute and return the sum of all items in the values attribute. You are encouraged to use Python's built-in sum function to assist in the implementation of your sum method. Doing so is illustrative of a pattern called delegation, where the implementation of some algorithm is delegated to existing algorithm. It should take no arguments and return a float. ones = Simpy([1.0, 1.0, 1.0]) print("Actual: ", ones. sum(), Expected: 3.0") one_to_nine = Simpy([]) one_to_nine.arange(1.0, 10.0) print("Actual: ", one_to_nine.sum(), - Expected: 45.0") Pythonarrow_forward
- Please help me with the assignment below The assignment: Make a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The driver class needs to have only 5 or 7 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.arrow_forwardcontinue from first question, Client class:The client program will allow entry of these data for several different student into an ArrayList and then perform some analysis and queries.Your client class (program) will provide the user with a menu to perform the following operations. You will also need to load the information of the students from a CSV file (student.csv) before displaying the menu. You only need one ArrayList and one menu for this. For the csv file, your first item can be U or G to differentiate whether the entry is creating a UndergraduateStudent object, or a GraduateStudent object. You can then decide how you want other data to be listed in the csv file. You should specify clearly in your documentation the data format of the CSV files used in this assignment.1. Quit (exit the program)2. Add (to the ArrayList) all the marks information about an undergraduate or graduate student by reading it from another CSV file. Your program will ask for the file name.3. Given student…arrow_forwardI already have the code for the assignment below, but there is some errors in the code. Please help me fix them. The assignment: Make a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help. The code: PhoneLookup.java import java.io.FileReader;import java.io.IOException;import java.util.Scanner; public class PhoneLookup{ public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in);…arrow_forward
- If a collection stores 10 objects, what value would be returned from a call to its size method?arrow_forwardYou are required to complete the LinkedList class. This class is used as a linked list that has many methods to perform operations on the linked list. To create a linked list, create an object of this class and use the addFirst or addLast or add (must be completed) to add nodes to this linked list(I created one linked list in TestLinkedList). I’ve already created the class for you and have some completed method in there, your job is to complete the empty methods.For every method you have to complete, you are provided with a header, Do not modify those headers( method name, return type or parameters). You have to complete the body of the method. public void add(T afterThis, T info) The parameter info will be the information the new node should contain, and the new node will be added after the node that contains the parameter afterThis as an information public void removeFirst() Removes the first node in the linked list. Hint: be aware of empty lists. public void removeLast() Removes…arrow_forwardYou are required to complete the LinkedList class. This class is used as a linked list that has many methods to perform operations on the linked list. To create a linked list, create an object of this class and use the addFirst or addLast or add(must be completed) to add nodes to this linked list(I created one linked list in TestLinkedList). I've already created the class for you and have some completed method in there, your job is to complete the empty methods. For every method you have to complete, you are provided with a header, Do not modify those headers(method name, return type or parameters). You have to complete the body of the method. public void add(T after This, T info) The parameter info will be the information the new node should contain, and the new node will be added after the node that contains the parameter after This as an information. public void removeFirst() Removes the first node in the linked list. Hint: be aware of empty lists. public void removeLast() Removes…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