Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Remember that and ArrayList is an array - based List ( ADT ) . You are implementing an ArrayList of integers. When the list is
Remember that and ArrayList is an arraybased List ADT
You are implementing an ArrayList of integers. When the list is initialized all elements are set to zero.
When removing an element, the value of any empty elements will be reset to zero.
Can you only fill in the blanks and not touch imports?
import java.io;
import java.math.;
import java.security.;
import java.text.;
import java.util.;
import java.util.concurrent.;
import java.util.function.;
import java.util.regex.;
import java.util.stream.;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
You need to be mindful of the capacity of your ArrayList, and may need to
adjust it beforeafter any of the following operation completes.
interface IArrayList
public int getSize;
public int getCapacity;
public int getint index;
public void addint value;
public void addAtIndexint value, int index;
public void removeint value;
public void removeAtIndexint index;
This method will remove all the elements from your ArrayList.
public void clear;
class ArrayList implements IArrayList
private int arr;
The maximum number of elements arr is able to hold, until resizing is
needed.
private int capacity;
This will hold number of elements in your ArrayList. Notice it's different
than the capacity!
private int size;
public ArrayListint capacity
this.capacity capacity;
this.arr new intcapacity;
public void print
String elements ;
for int i ; i this.capacity; i
elements this.arri;
if i this.capacity
elements ;
elements ;
String summary String.format capacity: d size: d elements: s
this.capacity, this.size, elements;
System.out.printlnsummary;
Write your code below here...
Use this as a helper method
private void doubleCapacity
Write your code here...
Use this as a helper method
private void halveCapacity
Write your code here...
implement the IArrayList.
Write your code here...
class Solution
public static void mainString args throws IOException
input handling
BufferedReader bufferedReader new BufferedReadernew
InputStreamReaderSystemin;
int capacity Integer.parseIntbufferedReaderreadLinereplaceAlls
$splittrim;
int operationCount
Integer.parseIntbufferedReaderreadLinereplaceAlls$split
trim;
bufferedReader.readLine;
ArrayList arrList new ArrayListcapacity;
IntStream.range operationCountforEachopCountItr
try
List theInput
Stream.ofbufferedReaderreadLinereplaceAlls$split
collecttoList;
String action theInput.get;
String arg theInput.size theInput.gettrim : null;
String arg theInput.size theInput.gettrim : null;
String arg theInput.size theInput.gettrim : null;
ProcessInputsarrList action, arg arg arg;
catch IOException exception
throw new RuntimeExceptionexception;
;
bufferedReader.close;
private static void ProcessInputsArrayList arrList, String action, String
arg String arg String arg
int result;
int value;
int index;
switch action
case "getSize":
result arrList.getSize;
System.out.printlnresult;
break;
case "getCapacity":
result arrList.getCapacity;
System.out.printlnresult;
break;
case "get":
index Integer.parseIntarg;
result arrList.getindex;
System.out.printlnresult;
break;
case "add":
value Integer.parseIntarg;
arrList.addvalue;
break;
case "addAtIndex":
value Integer.parseIntarg;
index Integer.parseIntarg;
arrList.addAtIndexvalue index;
break;
case "remove":
value Integer.parseIntarg;
arrList.removevalue;
break;
case "removeAtIndex":
index Integer.parseIntarg;
arrList.removeAtIndexindex;
break;
case "clear":
arrList.clear;
break;
case "print":
arrList.print;
break;
CAPACITY
OPERATIONCOUNT
add,
add,
add,
addAtIndex,
print
Sample Output
capacity: size: elements:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started