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 15E
Write some code that will use an iterator to interchange the items in every pair of items in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains “a”, “b”, “c”, “d”, “e”, and “f”, after the code runs, it will contain “b”, “a”, “d”, “c”, “f”, and “e”. You can assume that the list contains an even number of strings.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The 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.
You are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this homework.
The “data.txt” file has three lines of data
100, 110, 120, 130, 140, 150, 160
100, 130, 160
1@0, 2@3, 3@END
You need to
1. create an empty unsorted list
2. add the numbers from the first line to list using putItem() function.
Then print all the current keys to command line in one line using printAll().
3. delete the numbers given by the second line in the list by using deleteItem() function.
Then print all the current keys to command line in one line using printAll()..
4. putItem () the numbers in the third line of the data file to the corresponding location in
the list. For example, 1@0 means adding number 1 at position 0 of the list.
Then print all the current keys to command line in one…
1. 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…
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
Solve the differential equation dydx=xy1x+y+3 by finding h and k so that the substitutions x=u+h, y=v+k transfo...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
A sentence is in disjunctive normal form (DNF) if it is the disjunction of conjunctions of literals. For exampl...
Artificial Intelligence: A Modern Approach
Describe the function computed by the following Bare Bones program, assuming the functions inputs are represent...
Computer Science: An Overview (12th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
(De Morgans Laws) In this chapter, we discussed the logical operators , , | |, |, ^ and !. De Morgans laws can ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Trivia Game In this programming exercise, you will create a simple trivia game for two players. The program wil...
Starting Out with Python (4th Edition)
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
- 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…arrow_forwardWrite a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. import java.util.Scanner; public class CourseGradePrinter {public static void main (String [ ] args) {Scanner scnr = new Scanner(System.in);final int NUM_VALS = 4;int [ ] courseGrades = new int[NUM_VALS];int i; for (i = 0; i < courseGrades.length; ++i) {courseGrades[i] = scnr.nextInt();} /* Your solution goes here */ }}arrow_forwardYou can check whether a string is a substring of another string by using the find method in the str class. Write your own function to implementfind. Write a program that prompts the user to enter two strings and then checks whether the first string is a substring of the second string.arrow_forward
- Write 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 the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values. Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count. She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program. Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut). Plates.java import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Plates { private Map<String, Integer> plateMap;…arrow_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
- This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints. You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator. 1 def only_evens (1st: list[list[int]]) -> list[list[int]]: """Return a list of the lists in 1st that contain only even integers. 4 >>> only_evens ([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]]) [[4, 0, 6], [2]] 6. 8. even_lists = [] 10 for sublist in 1st: 11 12 # write your code here (please read above for a suggested approach) 13 14 return even_listsarrow_forwardThis problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist contains only even ints. You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator. 1 def only evens (1st: list[list[int]]) -> list[list[int]]: **"Return a list of the lists in 1st that contain only even integers. 2. 3. >>> only_evens ([[1, 2, 4], [4, e, 6], [22, 4, 3], [2]]) 4. [[4, e, 6], [2]] 8. even_lists = [] 10 for sublist in 1st: 11 12 13 14 return even_lists History Submit P Type here to search 100% 1:1 8°C Cloudy A 4) ENG 10/2arrow_forwardQ1. Let's assume that you have a variable "words" of type ArrayList, already filled with some values. Write the loop to go over each element in the list and count the total number of characters used for all words. In other words, call the method length() on each string and do the sum of all those numbers returned. Do not use a For-Each loop.arrow_forward
- Write a Java application CountryList. In the main method, do the following:1. Create an array list of Strings called countries.2. Add "Canada", "India", "Mexico", "Peru" in that order.3. Use the enhanced for loop to print all countries in the array list, one per line.4. Add "Spain" at index 15. Replace the element at index 2 with "Vietnam". You must use the set method.6. Replace the next to the last element with "Brazil". You must use the set method. You willlose one point if you use 3 in the set method. Do this in a manner that would replace thenext to the last element, no matter the size of the array list.7. Remove the object "Canada" Do not remove at an index. Your code should work if"Canada" was at a different location. There is a version of remove method that willremove a specific object.8. Get and print the first element followed by "***"9. Call method toString() on countries to print all elements on one line.10. Use the enhanced for loop to print all countries in the array list,…arrow_forwardImplement the fix_capitalization() function. fix_capitalization() has a string parameter and returns an updated string, where lowercase letters at the beginning of sentences are replaced with uppercase letters. fix_capitalization() also returns the number of letters that have been capitalized. Call fix_capitalization() in the print_menu() function, and then output the edited string followed by the number of letters capitalized. Hint 1: Look up and use Python functions .islower() and .upper() to complete this task. Hint 2: Create an empty string and use string concatenation to make edits to the string. Ex: Number of letters capitalized: 2arrow_forwardModify the algorithm described in the class to calculate the longest palindrome, such that there is enough information on the table to build the longest palindrome from the table. Hint: You can use similar data structure used for Longest common subsequence. Explain how you can rebuild a longest palindrome from the given string using this data structure.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
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