Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel 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
Please use java.
In this assignment, you will implement a class calledCustomIntegerArrayList. This class represents a fancy ArrayList that stores integers and supports additional operations not included in Java's built-in ArrayList methods.
For example, the CustomIntegerArrayList class has a “splice” method which removes a specified number of elements from the CustomIntegerArrayList, starting at a given index. For a CustomIntegerArrayList that includes: 1, 2, 3, 4, and 5, calling splice(1, 2) will remove 2 items starting at index 1. This will remove 2 and 3 (the 2nd and 3rd items).
The Cu stomIntegerArrayList class has 2 different (overloaded) constructors. (Remember, an overloaded constructor is a constructor that has the same name, but a different number, type, or sequence of parameters, as another constructor in the class.) Having 2 different constructors means you can create an instance of the CustomIntegerArrayList class in 2 different ways, depending on which constructor…
Write a java program called ArrayList_Practice. In this program, please do the following operations.
1.Complete a method called RedundantCharacterMatch(ArrayList<Character>
YourFirstName): the parameter of this method is an ArrayList<Character> whose elements
are the characters in your first name (they should be in the order appear in your first name,
e.g., if your first name is bob, then the ArrayList<Char> includes ‘b’, ‘o’, ‘b’.). The method
will check whether there exists duplicate characters in your name and return the index of
those duplicate characters. For example, when using bob as first name, it will return b: 0, 2.
2.
Create an ArrayList<Character> NameExample. All the characters of your first name will
appear twice in this ArrayList. For example, if your first name is bob, then NameExample
will include the following element {b,o,b,b,o,b}. Then, please use NameExample as
parameter for the method RedundantCharacterMatch(). If your first name is bob,…
Chapter 24 Solutions
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
- 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 correctarrow_forward4. 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.arrow_forwardPlease 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_forward
- Hello, can anyone help me with this problem. i want to run and compile this code, thank you.arrow_forwardProvide a different implementation of ChoiceQuestion. Instead of storing the choices in an array list, the addChoice method should add the choice to the question text. For this purpose, an addLine method has been added to the Question class. Use the following files: Question.java /** A question with a text and an answer.*/public class Question{ private String text; private String answer; /** Constructs a question with empty text and empty answer. */ public Question() { text = ""; answer = ""; } /** Sets the answer for this question. @param correctResponse the answer */ public void setAnswer(String correctResponse) { answer = correctResponse; } /** Checks a given response for correctness. @param response the response to check @return true if the response was correct, false otherwise */ public boolean checkAnswer(String response) { return response.equals(answer); } /** Add a line of text to…arrow_forwardplease send solutionarrow_forward
- I 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_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_forwardWrite a Java program that uses ArrayList and Iterator. It should input from user the names and ages of your few friends in a loop and add into ArrayList. Finally, it should use an Iterator to display the data in a proper format. ( Sample run of the program:-) List of my Friends Enter name and age [friend# 0] Khalid Al-shamri 22.5 Do you want to add another friend (y/n)? y Enter name and age [friend# 1] Rahsed Al-anazi 21.1 Do you want to add another friend (y/n)? y Enter name and age [friend# 2] Salem Al-mutairi 23.7 Do you want to add another friend (y/n)? n Here is the data you entered: 0. Khalid Al-shamri, 22.5 1. Rahsed Al-anazi, 21.1 2. Salem Al-mutairi, 23.7arrow_forward
- Java 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 use java In this assignment, you will implement a class called ArrayAndArrayList. This class includessome interesting methods for working with Arrays and ArrayLists.For example, the ArrayAndArrayList class has a “findMax” method which finds and returns themax number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, callingfindMax(array) will return 9.There are 4 methods that need to be implemented in the ArrayAndArrayList class:● howMany(int[] array, int element) - Counts the number of occurrences of the givenelement 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 givenarray.● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the givenarray.Each method has been defined for you, but without the code. See the javadoc for each methodfor instructions on what the method is supposed to do and how to write the code. It…arrow_forwardI already asked this question once, but I receivied it in C++ form and not Java. I do my Java programming in Apache NetBeans IDE 12.2. The question is below, but please let it be Java coding: Create a two-dimensional array of type double to contain the three different SD Marks (JD521, PRG521, and IP521) for six different students. A single array of type String must be used to store the student names (Maxwell, Carl, Gerhard, Paul, James, and Cena). Allow a user to enter in a number, ranging from 1 to 6, which will represent the student position in the table MCSD max and present the marks for each respecting module. The program can only stop when the user enter a number greater than 6. Printout the student name including the JD521, PRG521, and IP521 max, the total of marks and the average of all marks. Use a condition statement to decide that the student has passed or not (Pass rate is 70). Thank you.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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License