Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
11th Edition
ISBN: 9780134671581
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 24.3, Problem 24.3.5CP
If you change the code in line 33 in Listing 24.2, MyArrayList.java, from
E[] newData = (E[])(new Object[size * 2 + 1]);
to
E[] newData = (E[])(new Object[size * 2]);
the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
If a method given an ArrayList as a parameter calls a second method giving it the same ArrayList, and that second method deletes one of the elements, this will: (produce a non-deterministic result? trigger an error? have an effect? have no effect?) on the first ArrayList.
Java uses: (pass by reference? pass by value?) So when an object is passed to a method, what is actually passed is just : (the name of the object? a pointer to the object? the index of the object?) .
Select the correct answer
What is true after the execution of the following code?
ArrayList<String> arrayList = new ArrayList<String>();arrayList.add("a");arrayList.add("b");arrayList.add("c");arrayList.remove("b");
a.the arrayList will contain a, null, c
b.the arrayList will contain a, c
c.an exception is thrown
d.none of these is correct
4. Say we wanted to get an iterator for an ArrayList and use it to loop over all items and print
them to the console. What would the code look like for this?
5. Write a method signature for a method called foo that takes an array as an argument. The
return type is void.
6. What is the difference between remove and clear in ArrayLists.
Chapter 24 Solutions
Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
Ch. 24.2 - Prob. 24.2.1CPCh. 24.2 - Prob. 24.2.2CPCh. 24.2 - Prob. 24.2.3CPCh. 24.2 - Prob. 24.2.4CPCh. 24.3 - What are the limitations of the array data type?Ch. 24.3 - Prob. 24.3.2CPCh. 24.3 - Prob. 24.3.3CPCh. 24.3 - What is wrong if lines 11 and 12 in Listing 24.2,...Ch. 24.3 - If you change the code in line 33 in Listing 24.2,...Ch. 24.3 - Prob. 24.3.6CP
Ch. 24.3 - Prob. 24.3.7CPCh. 24.4 - Prob. 24.4.1CPCh. 24.4 - Prob. 24.4.2CPCh. 24.4 - Prob. 24.4.3CPCh. 24.4 - Prob. 24.4.4CPCh. 24.4 - Prob. 24.4.5CPCh. 24.4 - Prob. 24.4.7CPCh. 24.4 - Prob. 24.4.8CPCh. 24.4 - Prob. 24.4.9CPCh. 24.4 - Prob. 24.4.10CPCh. 24.5 - Prob. 24.5.1CPCh. 24.5 - Prob. 24.5.2CPCh. 24.5 - Prob. 24.5.3CPCh. 24.6 - What is a priority queue?Ch. 24.6 - Prob. 24.6.2CPCh. 24.6 - Which of the following statements are wrong?...Ch. 24 - (Implement set operations in MyList) The...Ch. 24 - (Implement MyLinkedList) The implementations of...Ch. 24 - (Use the GenericStack class) Write a program that...Ch. 24 - Prob. 24.5PECh. 24 - Prob. 24.6PECh. 24 - (Fibonacci number iterator) Define an iterator...Ch. 24 - (Prime number iterator) Define an iterator class...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Implement a performance-measuring environment simulator for the vacuum-cleaner world depicted in Figure 2.2 and...
Artificial Intelligence: A Modern Approach
Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total.
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
The ______ is the name of the structure type.
Starting Out with C++ from Control Structures to Objects (9th Edition)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction to Programming Using Visual Basic (10th Edition)
Lottery Application Write a program that simulates a lottery. The program should have an array of five integers...
Starting Out with C++ from Control Structures to Objects (8th 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
- Please use java. Show the steps with pictures. In this assignment, you will implement a class calledArrayAndArrayList. This class includes some interesting methods for working with Arrays and ArrayLists. For example, the ArrayAndArrayList class has a “findMax” method which finds and returns the max number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, calling findMax(array) will return 9. There are 4 methods that need to be implemented in the A rrayAndArrayList class: ● howMany(int[] array, int element) - Counts the number of occurrences of the given element in the given array. ● findMax(int[] array) - Finds the max number in the given array. ● maxArray(int[] array) - Keeps track of every occurrence of the max number in the given array. ● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the given array. Each method has been defined for you, but without the code. See the javadoc for each method for instructions on what the…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_forwardplease send solutionarrow_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_forwardI need anyone can check of my Hand class codes: "The getHandValue() method treats all Aces as having a value of 1. This needs to be corrected in the final version" Deck Class: import java.util.ArrayList;public class Hand { ArrayList<Card> hand; public Hand() { hand = new ArrayList<Card>(); } public void add(Card c) { hand.add(c); } public String toString() { String temp = "["; for (int i = 0; i < hand.size(); i++) { temp += hand.get(i); if (i < hand.size() - 1) { temp += ","; } } temp += "]"; return temp; } /* The getHandValue() method treats all Aces as having a value of 1. This needs to be corrected in the final version. */ public int getHandValue() { int total = 0; boolean hasAces = false; for (int i = 0; i < hand.size(); i++) { int value = hand.get(i).getValue(); if (value >…arrow_forwardA team member submitted the following code for you to review. Identify at least 5 things that would improve the code: package edu.school; import java.util.ArrayList; import java.util.Collections; public class DriversLicenseRepository extends ArrayList<Object> { public List<Object> updateExpirationDate(License license, Date temp) { ArrayList list = new ArrayList(); for(Object v : this) { if((((License)v.getLicenseNo()) == license.getLicenseNo(){ list.add(v); } } return list; } public void recordVote(Ballot ballot, int voter) { ArrayList newList = new ArrayList<>(); Election election = ElectionManager.getInstance(); for(Object v : this) { if(((Voter)v.id) == voter) { election.addVote(ballot, (Voter)v); } newList.add(v); } clear(); addAll(newList); } public Voter getLicense(String i) throws IllegalArgumentException{ if(get(i) instanceof License) { return get(0); } throw new…arrow_forward
- Only number 5arrow_forwardhow to answer the following question in java screen shot shows the ABList class Suppose a list names contains 8 elements. A call to names.set(8, "Albert") results in: A. an exception being thrown. B. an 8 element list with "Albert" as the last element. C. a 9 element list with "Albert" as the last element. D. a 9 element list with "Albert" as the next to last element. The only index-related method of the ABList class that can make good use of the protected find method is: A. add B. set C. get D. indexOf E. remove An application can indicate that it wants to use the "natural order" to order the elements of a SortedABList list by: A. passing the constructor an appropriate compareTo method. B. using the parameter-less constructor. C. using the standard list iteration approach. D. always adding elements to the front of the list. Suppose a list names contains 8 elements. A call to names.add(9, "Albert") results in: A. an exception being…arrow_forwardWhat is the output of the following Java code? ArrayList<String> names = new ArrayList<>(); names.add("James"); names.add("Mary"); names.add("Henry"); names.add("George"); names.add("Mary"); names.add("John"); names.add("Zachery"); Set names_wo_duplicate = new HashSet(names); Iterator set_val = names_wo_duplicate.iterator(); while(set_val.hasNext()) System.out.print(set_val.next() + ", "); Group of answer choices James, George, John, Zachery, Henry, Mary James, Mary, Henry, George, John, Zachery None of the above Code does not compile because of syntax errorsarrow_forward
- 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…arrow_forwardJava ArrayLists can only be filled with reference type data, so you cannot fill them with primitive type data. How can you work around this with integers? (How can you have an ArrayList filled with integers?)arrow_forwardPLEASE MAKE IT RUN LIKE THE EXPECTED PICTUREarrow_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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License