Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12, Problem 10E
Revise the class StringLinkedList in Listing 12.5 so that it can add and remove items from the end of the list.
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…
4. This question involves the process of taking a list of words, called wordList, and producing a formatted
string of a specified length. The list wordList contains at least two words, consisting of letters only.
When the formatted string is constructed, spaces are placed in the gaps between words so that as many spaces as
possible are evenly distributed to each gap. The equal number of spaces inserted into each gap is referred to as
the basic gap width. Any leftover spaces are inserted one at a time into the gaps from left to right until there are
no more leftover spaces.
The following three examples illustrate these concepts. In each example, the list of words is to be placed into
a formatted string of length 20.
Example 1: wordList: ["AP", "COMP", "SCI", "ROCKS"]
Total number of letters in words: 14
Number of gaps between words: 3
Basic gap width: 2
Leftover spaces: 0
Formatted string:
2
0 1
A
A|P| |
3
Basic gap width: 1
Leftover spaces: 2
Formatted string:
0
1
G R
Example 2:…
Can you please write the follwing in Java.
You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists.
Use an array of strings to store the 4 strings listed in the description.
Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below:
determine the fruits to display (step 3 below) and print them
determine if there are 3 or 4 of the same image
display the results
update the customer balance as necessary
prompt to play or quit
continue loop if customer wants to play and there's money for another game.
Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an ArrayList. You'll have to do…
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th 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.5 - What is the purpose of the FXML file?Ch. 12.5 - Prob. 32STQCh. 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
The spreadsheet in Microsoft Excel file Ch01Ex01_U10e.xlsx contains records of employee activity on special pro...
Using MIS (10th Edition)
List four types of systems that may require software safety cases, explaining why safety cases are required.
Software Engineering (10th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Use the debugger to investigate the clock-display project. Set breakpoints in the ClockDisplay constructor and ...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Create a flowchart that shows the necessary steps for making the cookies in the following recipe: Ingredients: ...
Starting Out With Visual Basic (8th Edition)
Can methods in the derived class directly access the base classs private members?
Starting out with Visual C# (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
- Write this program in Java using a custom method. Implementation details You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an…arrow_forward2. Revise the genericStack class we did in the class to implement it using an array instead of ArrayList. You need to check the array size before adding a new element. If it is full, create a new array that double the current size and copy the elements from the current to the new array and then add the new array. (2 points) 3. Use the genericStack class we did the class (not the one in question 2), implement the binary search public static <E extends Comparable<E>) int binarySearch (E[] list, E key) and a method that returns the maximum value element public static <E extends Comparable<E>) E max(E[] list (2 points)arrow_forwardCan someone assist in with answering this question please?arrow_forward
- java Write a program to do the following: Create an ArrayList of Student. Add 7 elements to the ArrayList. Use for each loop to print all the elements of an ArrayList. Remove an element from an ArrayList using the index number. Remove the element from an ArrayList using the content (element name).arrow_forwardWrite all the Members of the ArrayList Class?arrow_forwardUse the ArrayList class Add and remove objects from an ArrayList Protect from index errors when removing Practice with input loop Details: This homework is for you to get practice adding and removing objects from an ArrayList. The Voter class was used to create instances of Voters which held their name and a voter identification number as instance variables, and the number of instances created as a static variable. This was the class diagram: The constructor takes a string, passed to the parameter n, which is the name of the voter and which should be assigned to the name instance variable. Every time a new voter is created, the static variable nVoters should be incremented. Also, every time a new voter is created, a new voterID should be constructed by concatenating the string “HI” with the value of nVoters and the length of the name. For example, if the second voter is named “Clark Kent”, then the voterID should be “HI210” because 2 is the value of nVoters and 10 is the number…arrow_forward
- Can you help me please: Write a program to test various operations of the class doublyLinkedList. Your program should accept a list of integers from a user and use the doubleLinkedList class to output the following: The list in ascending order. The list in descending order. The list after deleting a number. A message indicating if a number is contained in the list. Output of the list after using the copy constructor. Output of the list after using the assignment operator. An example of the program is shown below: Enter a list of positive integers ending with -999: 83 121 98 23 57 33 -999 List in ascending order: 23 33 57 83 98 121 List in descending order: 121 98 83 57 33 23 Enter item to be deleted: 57 List after deleting 57 : 23 33 83 98 121 Enter item to be searched: 23 23 found in the list. ********Testing copy constructor*********** intList: 23 33 83 98 121 ********Testing assignment operator*********** temp: 23 33 83 98 121 Your program should use the value -999 to denote the…arrow_forwardIn F3, students will be tasked with taking input from a file to create an *Array* of FeetInches (2 parameters). When all the FeetInches have been stored, any FeetInches at least 1 foot will be converted and added to an *ArrayList* of Circles (one parameter). Students will then complete the compareTo method found in the Circle class, sort the ArrayList of Circles, and then output the radius' of the new circle. The first integer in the file input will tell us how many FeetInches objects will be made using the fileInput, and the numbers after are the data for those Objects. Use this first integer in your for Loops. A template with main, Circle, and FeetInches class, as well as the file input, is attached below. Please follow along with comments and reach out if you have any questions. package f3_template; public class Circle implements Comparable <Circle>{//attribute private int radius; //constructorspublic Circle(){radius=0;}public Circle(int r){radius=r;}//accessorspublic…arrow_forwardThe play method in the Player class of the craps game plays an entire game without interaction with the user. Revise the Player class so that its user can make individual rolls of the dice and view the results after each roll. The Player class no longer accumulates a list of rolls, but saves the string representation of each roll after it is made. Add new methods rollDice, getNumberOfRolls, isWinner, and isLoser to the Player class. The last three methods allow the user to obtain the number of rolls and to determine whether there is a winner or a loser. The last two methods are associated with new Boolean instance variables (winner and loser respectively). Two other instance variables track the number of rolls and the string representation of the most recent roll (rollsCount and roll). Another instance variable (atStartup) tracks whether or not the first roll has occurred. At instantiation, the roll, rollsCount, atStartup, winner, and loser variables are set to their appropriate…arrow_forward
- 1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or byentering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For example, if the list contains the following names: Charles Darwin Albert Einstein Issac Newton Tony Hoare Grace Hopper Edgar Dijkstra Ada Lovelace Charles Babbage Stephen Hawking Your program should output:The first name in the list in alphabetical order is: Ada Lovelace The last name in the list in alphabetical order is: Tony Hoarearrow_forwarden "MyDoubleLinkedList" class: te a method called "PrintListInReverse" to print the list backward. example, Givenarrow_forward3. Create an ArrayList of strings to store the names of celebrities or athletes. Add five names to the list. Process the list with a for loop and the get() method to display the names, one name per line. Pass the list to avoid method. Inside the method, Insert another name at index 2 and remove the name at index 4. Use a foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the arraylist and use it to display the list one more time. See Sample Output. SAMPLE OUTPUT Here is the list Lionel Messi Drake Adele Dwayne Johnson Beyonce Here is the new list * Lionel Messi * Drake * Taylor Swift * Adele * Beyonce Using an iterator, here is the list Lionel Messi Drake Taylor Swift Adele Beyoncearrow_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