Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java Goal: In this lab, you will gain more experience with arrays and ArrayLists in Java by implementing a simplified version of Java's ArrayList.

In java
image text in transcribed
Goal: In this lab, you will gain more experience with arrays and ArrayLists in Java by implementing a simplified version of Java's ArrayList. Problem: You will write the class IntArrayList that will work like an ArrayList of integers. You may not use Java's ArrayList class (or any other Java data structure other than the array) for this lab. Task 1: Start the IntArrayList class by declaring two fields: the store, which is the array that will hold the integers, and size, which indicates the number of integers in the list. Initialize both fields in a default (no parameters) constructor. Assume a default array size of I0 Task 2: Add the following methods to the IntArrayList class: add-given an integer, this method adds the integer to the end of the list. Each integer is placed in the array. Don't worry about the array being full at this point. get-given an index, this method returns the integer in the list at that index. you can assume the given index is valid. size-returns the number of integers in the list (that is the number of integers added to the list...not the length of the array . For this lab, . Write a main method to test your class so far. Create an IntArrayList object and add all of the even numbers from 2-20 to the list. Use a regular for loop to print all of the numbers in the list. If this works, continue Task 3: Add the following methods to the IntArrayList class: indexOr-given an integer, this method returns the index of that integer within the list if the integer is present or-1 if it is not. contains-given an integer, this method returns true if the integer is in the list and false if t is not remove-given an integer, this method finds the first occurrence of that integer in the list and removes that integer from the list. Treat the integer as an element in the list, not an array index. . Modify the main method to test your class. Make sure to print the integers in the list after removing an integer to make sure the list was updated correctly Task 4: Modify the add method so that the list can neverbe full. When an integer is added and the array is full, this method must now create a larger array and copy the integers from the current array to the larger array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions