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
Concept explainers
Question
Chapter 12.1, Problem 2STQ
Program Plan Intro
“set” method in “ArrayList” class:
- • This method is used to replace the value at the position specified by index with the given value.
- • Users can replace any existing element for a particular index using “set” method.
Example:
The example for replacing string for index “4” is given below:
Consider, “nameList” is an object of class “ArrayList<String>”.
User can replace the string “Rose” to the list “nameList” at index “4” which is given below:
nameList.set(4, "Rose");
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question 10
Create a class that implements a compressed trie for a set of strings. The class should have a constructor that takes a list of strings as an argument, and the class should have a method that tests whether a given string is stored in the trie. JAVA PLZ!
. . .
This code should be working at repl.it
Write a Java Console application in which you initialize an arraylist with 10 String values. For example, 10 colour names, or fruit names, or veg names, or car names, etc. Display all the values in the list in a neat tabular format. Randomly select a value from the array. Now allow the user 3 chances to guess the value. After the first incorrect guess provide the user with a clue: the first letter of the randomly selected word. After the second incorrect guess provide the user with another clue: the number of letters in the word. Once the user correctly guesses the word, remove that word from the list. Display the number of items in the list. The user must have the option to play again.
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
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
- This program is going to maintain a list of customers’ names and bank account balances. 1. Create a class called CustomerList with a main method that instantiates an ArrayList of String objects called customerName. Invoke the add method to add the following names into the ArrayList: Cathy Ben Jorge Wanda Freddie 1. Print each name in the ArrayList using a for a loop. 2. Create another ArrayList object called customerBalance, to save users’ balance. What is the type of this ArrayList? double or Double? You just need to declare this ArrayList and leave it empty for now. 3. For each customer, print the name and ask the user to enter the initial balance for this customer. Save the initial balance into ArrayList customerBalance. Use a loop to get this done for all 5 customers. The program should print out this for the first customer: Example: Please enter the account balance for Cathy: (waiting for user’s input …) Code: for(int i=0; i<5;i++) { Print(“Please enter the account balance…arrow_forwardWrite code that creates an ArrayList that can hold String objects. Add the names of three cars to the ArrayList, and then display the contents of the ArrayList.arrow_forwardCan help in java String [] names = {"Dimo Ivanov", "Yani Yanev", "Ana Popova", "Nelly Angelova"}; 1. Get the arrays of names and surnames containing initial and second names, respectively (first determine the position of the space in the previous name with the indexOf () method of the String class). Display the arrays. 2. Sort the first_names array 3. Enter a name from the console using Scanner, look for an entered name contained in the first_names array and display the resultsarrow_forward
- In this programming challenge, you will create a simple trivia game for two players. The program will work like this: • Read the contents of the trivia.txt file into an ArrayList . • Starting with player 1, each player gets a turn at answering one trivia question. (For instance, if there are 10 questions, 5 for each player.) When a question is displayed, four possible answers are also displayed. Only one of the answers is correct, and if the player selects the correct answer, he or she earns a point. • After answers have been selected for all of the questions, the program displays the number of points earned by each player and declares the player with the highest number of points the winner, same as the sample execution. You are to design a Question class to hold the data for a trivia question. The Question class should have String fields for the following data: • A trivia question • Possible answer 1 • Possible answer 2 • Possible answer 3 • Possible answer 4 • The number of the…arrow_forwardProject Description: In this project you implement an ArrayStack ADT and use the stack for implementing the following methods: a) Reverse an array of Words: Accept an array of words as input parameter and return an array of words in reverse order. Use the method signature: public static String[] reverseWords (String[] wordList) Example Input: Bird Cat Dog Elephant Output: Elephant Dog Cat Birdarrow_forwardProject Description: In this project you implement an ArrayStack ADT and use the stack for implementing the following methods: a) Reverse an array of Words: Accept an array of words as input parameter and return an array of words in reverse order. Use the method signature: public static String[] reverse Words (String[] wordList) Example Input: Bird Cat Dog Elephant Output: Elephant Dog Cat Birdarrow_forward
- P1: Name Search. Download the text file names.txt attached below. It contains a list of 65 female first names in upper case letters. In Eclipse, insert this file into your Java project folder. Implement two static methods: • tringSort: It will sort the String array provided as an argument using one of the sorting algorithms presented in class (selection or insertion). • stringSearch: It will search the String array provided as its first argument for the String value provided as its second argument using the binary search algorithm presented in class. The main method reads the 65 names from the file names.txt and inserts each one into an array. This array is then sorted using the stringSort method. The stringSearch method is then used to search for different names inputed by the user.arrow_forwardin c# Write a console app that inputs a sentence from the user (assume no punctuation), then determines and displays ONLY THE DUPLICATE words in alphabetical order. Treat uppercase and lowercase letters the same. [Hint: You can use string method Split with no arguments, as in sentence.Split(), to break a sentence into an array of strings containing the individual words. By default, Split uses spaces as delimiters. Use string method ToLower before calling Split.]arrow_forward1. Write a Java program to create a new array list, add some colors (string) and print out the collection. The list should contain color "green". 2. Change the previous program to insert an element into the array list at the first position. 3. Change the application to print out the index of color "green". 4. Change the previous application to replace "green" value with "yellow". 5. Change the previous application to remove the third element from the list. 6. Change the application to sort the list of colors. 7. Change the application to shuffle the list of colors. 8. Change the application such that it swaps colors "Orange" and "Red". 9. Change the application to copy the current list into a new list. 10. Change the application to trim the capacity of the initial array list to the current list size. 11. Change the application to empty the second list. 12. Change the application to test (print out a message) if the second list is empty. 13. Change the application to increase the…arrow_forward
- You 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_forwardIn the C programming language Suppose you are given an array of integers. You want to insert a number x to the array and rearrange so that all the elements are less than or equal to x are before x, and the elements after x are greater than x. For example, suppose the list is {3, 2, 7, 0 1, 5}and x is 4, since3, 2, 0, and 1,are less than or equal to 4,7and 5 are greater than 4, the new array is {3, 2, 0, 1, 4, 7, 5}.The new array has the length of n+1 where n is the length of the input array. Example input/output #1: Enter the length of the array: 10 Enter the elements of the array: 3 5 14 03 92 8 11 Enter the number for insertion: 3 Output: 3 1 0 3 2 3 5 4 9 8 11 Example input/output #2: Enter the length of the array: 8 Enter the elements of the array: 5013 4 1 7 3 5 Enter the number for insertion: 6 Output: 5 0 4 1 356 13 7 1) Name your program arrays.c 2) Include the rearrange( ) function to rearrange the array: void rearrange(int *a, int n, int insert, int *b); a…arrow_forwardwrite a public static method named search that two parameters: a one-dimensional string array and string You need to search for the given array and return the number of occurrences of the string in the arrayarrow_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