Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12, Problem 13E
Write some code that will use an iterator to duplicate every item in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains “a”, “b”, and “c”, after the code runs, it will contain “a”, “a”, “b”, “b”, “c”, and “c”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Import the ArrayList and List classes from the java.util package to create a list of phone numbers and also import the HashSet and Set classes from the java.util package to create a set of unique prefixes.
Create a class called PhoneNumberPrefix with a main method that will contain the code to find the unique prefixes.
Create a List called phoneNumbers and use the add method to add several phone numbers to the list.
List<String> phoneNumbers = new ArrayList<>(); phoneNumbers.add("555-555-1234"); phoneNumbers.add("555-555-2345"); phoneNumbers.add("555-555-3456"); phoneNumbers.add("444-444-1234"); phoneNumbers.add("333-333-1234");
Create a Set called prefixes and use a for-each loop to iterate over the phoneNumbers list. For each phone number, we use the substring method to extract the first 7 characters, which represent the prefix, and add it to the prefixes set using the add method.
Finally, use the println method to print the prefixes set, which will contain all of…
PLEASE HELP FAST, java
Write a program that creates an ArrayList and adds a Loanobject, a Date object, a string, and a Circle object to the list, and use a loop todisplay all the elements in the list by invoking the object’s toString() method.
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Ch. 12.1 - Suppose aList is an object of the class...Ch. 12.1 - Prob. 2STQCh. 12.1 - Prob. 3STQCh. 12.1 - Prob. 4STQCh. 12.1 - Can you use the method add to insert an element at...Ch. 12.1 - Prob. 6STQCh. 12.1 - Prob. 7STQCh. 12.1 - If you create a list using the statement...Ch. 12.1 - Prob. 9STQCh. 12.1 - Prob. 11STQ
Ch. 12.1 - Prob. 12STQCh. 12.2 - Prob. 13STQCh. 12.2 - Prob. 14STQCh. 12.2 - Prob. 15STQCh. 12.2 - Prob. 16STQCh. 12.3 - Prob. 17STQCh. 12.3 - Prob. 18STQCh. 12.3 - Prob. 19STQCh. 12.3 - Write a definition of a method isEmpty for the...Ch. 12.3 - Prob. 21STQCh. 12.3 - Prob. 22STQCh. 12.3 - Prob. 23STQCh. 12.3 - Prob. 24STQCh. 12.3 - Redefine the method getDataAtCurrent in...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.4 - Revise the definition of the class ListNode in...Ch. 12.4 - Prob. 30STQCh. 12 - Repeat Exercise 2 in Chapter 7, but use an...Ch. 12 - Prob. 2ECh. 12 - Prob. 3ECh. 12 - Repeat Exercises 6 and 7 in Chapter 7, but use an...Ch. 12 - Write a static method removeDuplicates...Ch. 12 - Write a static method...Ch. 12 - Write a program that will read sentences from a...Ch. 12 - Repeat Exercise 12 in Chapter 7, but use an...Ch. 12 - Write a program that will read a text file that...Ch. 12 - Revise the class StringLinkedList in Listing 12.5...Ch. 12 - Prob. 12ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 14ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 17ECh. 12 - Revise the method selectionSort within the class...Ch. 12 - Repeat the previous practice program, but instead...Ch. 12 - Repeat Practice Program 1, but instead write a...Ch. 12 - Write a program that allows the user to enter an...Ch. 12 - Write a program that uses a HashMap to compute a...Ch. 12 - Write a program that creates Pet objects from data...Ch. 12 - Repeat the previous programming project, but sort...Ch. 12 - Repeat the previous programming project, but read...Ch. 12 - Prob. 9PPCh. 12 - Prob. 10PPCh. 12 - Prob. 11PPCh. 12 - Prob. 12PPCh. 12 - Prob. 13PPCh. 12 - Prob. 14PPCh. 12 - Prob. 15PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Practice Problem 2.42 (solution page 156) Write a function divl6 that returns the value x/16 for integer argume...
Computer Systems: A Programmer's Perspective (3rd Edition)
T F Its safe to assume that all uninitialized variables automatically start with 0 as their value.
Starting Out with C++ from Control Structures to Objects (8th Edition)
Assuming that intNumber is an integer variable, what value will each of the following statements assign to it? ...
Starting Out With Visual Basic (7th Edition)
How is a constructor named?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Celsius Temperature Table The formula for converting a temperature from Fahrenheit to Celsius is C=59(F32) wher...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
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
- In this assignment, you will compare the performance of ArrayList and LinkedList. More specifically, your program should measure the time to “get” and “insert” an element in an ArrayList and a LinkedList.You program should 1. Initializei. create an ArrayList of Integers and populate it with 100,000 random numbersii. create a LinkedList of Integers and populate it with 100,000 random numbers2. Measure and print the total time it takes to i. get 100,000 numbers at random positions from the ArrayList 3. Measure and print the total time it takes to i. get 100,000 numbers at random positions from the LinkedList 4. Measure and print the total time it takes to i. insert 100,000 numbers in the beginning of the ArrayList 5. Measure and print the total time it takes to i. insert 100,000 numbers in the beginning of the LinkedList 6. You must print the time in milliseconds (1 millisecond is 1/1000000 second).A sample run will be like this:Time for get in ArrayList(ms): 1Time for get in…arrow_forward1. Write a method called doubleListthat takes an ArrayList of strings as a parameter and replaces every string with two of that same string. For example, if the list stores the values ["how", "are", "you?"] before the method is called, it should store the values ["how", "how", "are", "are", "you?", "you?"] after the method finishes executing.In your program1, you also need to create a class namedProgram1.java, where you are going to construct some arralylists to test the doubleList within the static void main method. In the output, it will print out the original list and the new list after calling the doubleList method. 2.Write a method called filterRange that accepts an ArrayList of integers and two integer values min and max as parameters and removes all elements whose values are in the range min through max (inclusive). For example, if a variable calledlist stores the values [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7], the call of filterRange(list, 5, 7);should remove all values…arrow_forwardImport the HashMap and Map classes from the java.util package. Within the main method, a sentence is declared as a string variable and assigned the value "This is a test sentence with no repeating words". Split the sentence into words using the split method and store the result in a String array called "words". Create a new Map called "wordFrequency" that stores each word as a key and the frequency of the word in the sentence as the corresponding value using the HashMap implementation. Use a for loop to iterate through each word in the "words" array. Within the for loop, the code should use the containsKey method to check if the word is already in the Map. If the word is already in the Map, its frequency should be incremented by 1. Use the put method to add the word as the key and the incremented frequency as the value to increment it. If the word is not in the map, add it as a new key with a frequency of 1 as its value. Outside of the for loop, use System.out.println to…arrow_forward
- Trying this again since part of my question keeps disappearing Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts 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…arrow_forwardImplement unique method that takes an ArrayList as input and returns an ArrayList withexactly a single occurrence of each element from the input list. For example, if the input listcontains 5, 6, 7, 6, 3, 5, 5, 4 then the output list should have 5, 6, 7, 3, 4.Note: (1) You may assume that the ArrayList has a specific type of elements in it. In the class, we assumedit to have String type values. (2) You may only work with ArrayList(s).arrow_forwardThe String class implements Comparable, which means that two strings can be compared to each other. However, the default implementation orders strings based on the ASCII values of their characters, which means that strings that begin with an uppercase letter are always ordered before strings that begin with a lowercase letter. This means that the string “Zoo” would be ordered before the string “aardvark”. Write a Comparator that compares two strings alphabetically so that “aardvark” is ordered before “Zoo”. Hint: convert both strings to upper or lowercase before comparing them.arrow_forward
- Hi, I am not sure what's wrong with my code. Can you please check why it is giving me an error? In the starter file is a partial implementation of a doubly-linked list in DoublyLinkedList.java. We will write three new methods in this class to provide additional functionality. Write a method addFirst that adds a new element at the beginning of a DoublyLinkedList. Write a method addLast that adds a new element at the end of a DoublyLinkedList. Write a method removeFirst that removes and returns the first element of a DoublyLinkedList. Try to keep your implementations as simple as possible. For example, recall this definition of addFirst in the (Singly) LinkedList class: public void addFirst(E value) { head = new Node(value, head); } In the DoublyLinkedList class, you will need to keep the three instance variables head, tail, and count updated in all methods. Note that addFirst and addLast will be symmetric to each other, as will removeFirst and removeLast (provided in the…arrow_forwardWrite a line (or lines) of code that uses a list that has been previously defined, named word_list, along with a string value entered by the user beforehand, named find, to print out the percent of the occurrence of that word in the list. As an example, if your word_list looked like this: ['the', 'word', 'I', 'am', 'looking', 'for', 'is', 'called', 'my', 'word'] And find was the string 'word' The Example Output would look like this: 20.00% of the list is word Otherwise, if your word_list looked like this: ['another', 'word', 'that', 'is', 'being', 'found', 'is', 'terracotta'] And find was the string 'looking' That Example Output would look like this: 0.00% of the list is lookingarrow_forwardImplement a lastIndex method for the LinkedIntList class you worked on for HW4. This method takes an int argument and returns the largest index such that the int argument appears at that index in the list. If the int argument does not appear in the list, then -1 is returned. For example if the list example contained the numbers [4, -1, 2, 7, -1, 3] in that order, then example.lastIndex(-1) should return 4 and example.lastIndex(5) should return -1. In the text area below, write the definition of the lastIndex method. (In other words, write the code that should replace the //TODO comment.) Your code cannot call any methods. public class LinkedIntList { private class Node { private int item; private Node next; public Node() {} public Node(int number, Node nextNode) { item = number; next = nextNode; } } private Node first; // first node of the list public LinkedIntList() { first = null;…arrow_forward
- 7. You could create a circular list from a single- linked list by executing the statement. а. tail.next = head b. head. prev = next c. tail. head next d. head.tail = prev 8. How much time does an ArrayList add a new element to the beginning of the list if n is the size of the ArrayList? а. О(1) b. 0(n) c. O(n²) d. 0(log n) 9. How much time does an ArrayList add a new element to the end of the list if n is the size of the ArrayList? a. 0(1) b. 0(n) c. O(n2) d. 0(log n)arrow_forwardCould somebody assist me with me? I'd very much appreciate itarrow_forwardGiven that an ArrayList of Strings named friendList has already been created and names have already been inserted, write the statement necessary to change the name "Tyler", stored at index 8, to "Bud". This is needed in Javaarrow_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
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY