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.4CP
What is wrong if lines 11 and 12 in Listing 24.2, MyArrayList.java,
for (int i = 0; i < objects.length; i++)
add(objects[i]);
are replaced by
data = objects;
size = objects.length;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Implement the function below.
void swap(int pos1, int pos2){}
Initial code to be completed:
class ArrayList : public List { int* array; int index; int capacity; void dyn_all_add(){ int cap = ceil(capacity * 1.5); array = (int*)realloc(array,cap * sizeof(int)); capacity = cap; }
void dyn_all_rem(){ int cap = capacity - (capacity/3); array = (int*)realloc(array,cap * sizeof(int)); capacity = cap; }
public: // CONSTRUCTOR ArrayList() { capacity = 4; array = (int*)malloc(capacity); index = 0; }
int add(int num) { if (index == capacity){ dyn_all_add(); } *(array + index) = num; index++; return index; }
int get(int pos){ if (pos-1 < index){ return *(array + pos-1); } return -1; } int size(){ return index; }…
void doo(list &L){
int item,a,p=L.size()-1; L.retrieve(p,a);
for(int i=0;i
JAVA:
Consider the following ArrayList:
ArrayList myList = new ArrayList<Insect>()
Using polymorphism, what type of objects could you put into this ArrayList? (Select all that apply)
Group of answer choices:
A: StagBeetle
B: Ant
C: Beetle
D: AntColony
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
Suppose you have a chess program that can evaluate 10 million nodes per second. Decide on a compact representat...
Artificial Intelligence: A Modern Approach
Passing arguments to base classes constructors solves the problem of selecting a base class constructor in inhe...
Starting Out with C++: Early Objects
TestScores Class Write a class named TestScores. The class constructor should accept an array of test scores as...
Starting Out with C++ from Control Structures to Objects (9th Edition)
In C# code, each opening brace must have a corresponding closing brace at some point later in the program.
Starting out with Visual C# (4th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Using MIS (10th Edition)
Write a program to print the corresponding Celsius to Fahrenheit table.
C Programming Language
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
- 1 import numpy as np from Interfaces import List 3 4 v class ArrayList (List): 5 6 ArrayList: Implementation of a List interface using Arrays. 7 8 v def _init_ (self): 9 10 -_init_: Initialize the state (array, n and j). 11 12 self.n = e self.j = e self.a = self.new_array (1) 13 14 15 16 v def new_array (self, n : int) ->np.array: 17 18 new_array: Create a new array of size n Input: 19 20 n: the size of the new array 21 Return: 22 An array of size n 23 24 return np.zeros (n, np.object) 25 26 v def resize(self): 27 28 resize Create a new array and copy the old values. 29 30 pass 31 32 y def get (self, i : int) -> object: 33 34 get: returns the element at position i 35 Inputs: 36 i: Index that is integer non negative and at most n 37 38 pass 39 40 v def set (self, i : int, x : object) -> object: 41 42 set: Set the value x at the indexi. 43 Inputs: 44 i: Index that is integer non negative and at most n 45 x: Object type, i.e., any object 46 47 pass 48 49 def append (self, x : object) : y…arrow_forwardI have the following code in java: import java.util.ArrayList;import java.util.Scanner; public class Auxiliar { static ArrayList<Animal> animales = new ArrayList<>(); static void imprimirAnimales() { for (Animal animal : animales) { System.out.println("Nombre: " + animal.getNombre() + ", Especie: " + animal.getEspecie() + ", Edad: " + animal.getEdad()); }} public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int opcion = 0; while (opcion != 5) { System.out.println("¿Qué acción desea realizar?"); System.out.println("1. Añadir animal"); System.out.println("2. Modificar animal"); System.out.println("3. Eliminar animal"); System.out.println("4. Imprimir lista de animales"); System.out.println("5. Salir"); opcion = scanner.nextInt(); scanner.nextLine();…arrow_forward2D-DP-3 int getLowestFromArray(int myList[], int size) int i; int lowestIndex = 0; for (i = 1; i myList[i]) lowestIndex = i; return lowestIndex; int main() int cData[2][5] = {{12, 5, 4, 7, 8}, {6, 35, 3, 27, 8}}; int i, lowest; for (i = 0; i < 2; i++) lowest = printf("%d\n", lowest); return 0; Given the code segment above, what will be needed to complete the code above? Assume the necessary libraries and functions are included and implemented. Encoding Instructions: Write your answers with NO SPACES. Answers not accepted by automatic checking in AnimoSpace due to not complying with the encoding instructions will not be given considerations.arrow_forward
- The statement "Linear collection of self-referential class objects, called nodes, connected by pointer links" is best describing a/an 7. O A. data structure B. union O c. array list O D. linked listarrow_forwardAnswer for.Write a Python Code for the given constructor and conditions: Given Constructor: def __init__ (self, a) Pre-condition: Array cannot be empty. Post-condition: This is the default constructor of MyList class. This constructor creates a list from an array..arrow_forwardWrite a class TouristSpot that has the data members; name of tourist spot, state in which it lies. Create an array list of n places and write a function that takes array list as an argument to identify a state that has more than one tourist spot. Java Programarrow_forward
- Q1. Write the following method that returns thesmallest element in an ArrayList:public static <E extends Comparable<E>> E min(ArrayList<E> list).arrow_forwardJava Objects and Linked Data: Select all of the following statements that are true. The Java Class Library's class ArrayList implements the LinkedList interface. In Java, when one reference variable is assigned to another reference variable, both references then refer to the same object. In Java, the "equals"-method that any object inherits can be overwritten to compare objects field by field.arrow_forwardCreate a class ArrayList with the following functionalities as follow: ArrayList(); void PushBack(T Value); // Grow by factor of 1.5 at each insertion T operator [](int index)const; T& operator [](int index); friend ostream& operator >> (ostream& out, ArrayList & Other); ~ArrayList();arrow_forward
- Java code 8. Given an existing ArrayList named friendList, find the first index of a friend named Sasha and store it in a new variable named index.arrow_forwardJava with screen shot pleasearrow_forwardTask: make AList support the for-each syntax. This will require that you make your class implement Iterable<T>. import java.util.Arrays;import java.util.Iterator;public class AList<T>{private T[] items;private int size;public AList() {items = (T[]) new Object[1];size = 0;}public void addLast(T x) {//items.length is our capacity if(size == items.length){ //doubling capacity of array grow(items.length * 2);}items[size] = x;size++;}public void addFirst(T x) {T[] newItems =(T[]) new Object[items.length+1]; newItems[0] = x; System.arraycopy(items,0, newItems,1, size);items = newItems; size++;}public T removeLast(){ T itemToRemove = items[size - 1];items[size - 1] = null;size--;return itemToRemove;}public T get(int i) {return items[i];}public T getFirst(){return items[0];}public T getLast(){ return items[size-1];}public int size() {return size;}private void grow(int capacity) {T[] expandedItems = (T[]) new Object[capacity]; System.arraycopy(items, 0, expandedItems, 0,…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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License