Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java ArrayList is a widely used inbuilt Java class. In this assignment, we are going to implement a simplified version of ArrayList to better understand

java
image text in transcribed
ArrayList is a widely used inbuilt Java class. In this assignment, we are going to implement a simplified version of ArrayList to better understand its internal working mechanism. Programming Tasks: 1. (3 points) Define a class whose name is SimpleArrayList, It has the following data fields: 1. The reference of a double array which is used to keep the elements in the array list. 12. An integer variable to indicate the actual size of the above array. is. A constant defining the default physical size 10 of the array. 2. (2 points) Define a constructor which can be used to create an empty array using the default physical size. 2. (2 points) Define a method doubleCapacity which doubles the current physical size of the array. Notice that the filled content of the array should not be changed. 4. (2 points) Define a method add which inserts the given double value at the given position in the array: public void adid(int index, double value) You are required to call the method defined in the previous task when the array is already full. You also need to check if the given index is out of bounds. If so, an IndexOutofBoundsException exception should be thrown. s. (2 points) Define a method remove which deletes the element in the given position and returns its value. public double remove (int index) 6 (1 point) Define a method get which returns the value in the given position. public double get(int index) 7. (2 points) Define a method indexof which returns the index of the first occurrence of the given value. public double indexof (double value) 8. ( 1 point) Define a toString method that returns a string representation of the filled content of the array. Notice that the unused cells should not be included in the string. Q. (5 points) Your implementation should pass the following test program: Q1. (1 point) Create an empty object of SimpleArraytist. 92. ( 2 points) Write a loop to add the following numbers at the end of the list: 2,4,6,8,10,12,14,16,18,20. 93. (I point) Add the value 100 to the position of 10 (index). This insertion should be successful. 9.4 (1 point) Add the value 1000 to the position of 12 (index). This insertion should produce an exception which should be caught by your test program

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions