SlideShare a Scribd company logo
java
I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so
much for your help. This is the problem and my code will be on the bottom.
Problem #1 and Only
Dynamic Array of Integers Class
Create a class named DynamicArray that will have convenient functionality similar to JavaScripts
Array object and Javas ArrayList class. The class allows to store array of integers that can grow
and shrink as needed, search for values, remove elements, etc.
You are not allowed to use ArrayList object as well as any methods from java.util.Arrays
class.
Please see the list of required features and methods below.
private int array[] You MUST store the data internally in a regular partially-filled array of integers.
Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be
discussed below.
private int size. This variable stores the number of occupied elements in the array. Set to 0 in the
constructor.
Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates
array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0
or negative, IllegalArgumentException is being thrown.
No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to
0.
Copy constructor. The constructor takes an object of type DynamicArray as a parameter and
copies it into the object it creates. The constructor throws IllegalArgumentException if the object
that was passed to copy from is null.
int getSize() returns the number of occupied elements in the array.
int getCapacity() returns the actual size (length) of the partially-filled array
int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the
private array field, make a copy of it.
int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO
NOT return the private array field. Instead, allocate memory for the new array, copy the occupied
portion of the field into that new object, and return the new array.
public void push(int num) adds a new element to the end of the array and increments the size
field. If the array is full, you need to increase the capacity of the array:
Create a new array with the size equal to double the capacity of the original one.
Copy all the elements from the array field to the new array.
Add the new element to the end of the new array.
Use new array as an array field.
Make sure your method works well when new elements are added to an empty DynamicArray.
public int pop() throws RuntimeException removes the last element of the array and returns it.
Decrements the size field. If the array is empty a RuntimeException with the message Array is
empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger
than the number of occupied elements (size), it is time to shrink the array:
Create a new array with the size equal to half of the capacity of the original one.
Copy all the elements from the array field to the new array.
Use new array as an array field.
int get(int index) throws IndexOutOfBoundsException returns element of the array with the
requested index. If the index provided is too large or negative, the IndexOutOfBoundsException is
thrown with the message Illegal index.
int indexOf(int key) returns the index of the first occurrence of the given number. Returns -1 when
the number is not found.
void add(int index, int num) throws IndexOutOfBoundsException adds a new element (passed as
parameter num) to the location of the array specified by index parameter. If the index is larger than
size of the array or less than 0, IndexOutOfBoundsException is thrown. When adding the element
into the middle of the array, youll have to shift all the elements to the right to make room for the
new one. If the array is full and there is no room for a new element, the array must be doubled in
size. Please follow the steps listed in the push() method description to double the capacity of the
array.
int remove ( int index) throws IndexOutOfBoundsException removes and returns the value of an
element at the specified position in this array. When the element is removed from the middle of the
array, all the elements must be shifted to close the gap created by removed element. If the index
value passed into the method is more or equal to the size or less than 0 the
IndexOutOfBoundsException must be thrown. At this point check the capacity of the array. If the
capacity is 4 times larger than the number of occupied elements (size), it is time to shrink the
array.
boolean isEmpty() returns true if the size of the array is 0.
String toString() returns an array as a string of comma-separated values. Sample: [1, 2, 3, 4]
boolean equals(DynamicArray obj) compares two objects (this one and the one passed as
parameter) element-by-element and determines if they are exactly the same. The capacity of the
two objects is not being compared and can be different.
MY CODE;
public class DynamicArray
{
private int Array[];
private int size;
// Constructor with parameter
public DynamicArray(int capacity)
{
if (capacity <= 0)
{
throw new IllegalArgumentException("Invalid capacity: " + capacity);
}
array = new int[capacity];
size = 0;
}
// No-argument constructor
public DynamicArray()
{
this(3);
}
// Copy constructor
public DynamicArray(DynamicArray other)
{
if (other == null)
{
throw new IllegalArgumentException("Cannot copy from null object");
}
array = new int[other.array.length];
System.arraycopy(other.array, 0, array, 0, other.size);
size = other.size;
}
public int getSize()
{
return size;
}
public int getCapacity()
{
return array.length;
}
public int[] getArray()
{
return Arrays.copyOf(Array, Array.length);
}
public int[] toArray()
{
return Arrays.copyOf(array, size);
}
public void push(int num)
{
if (size == array.length)
{
int[] newArray = new int[array.length * 2];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
}
array[size++] = num;
}
public int pop()
{
if (size == 0)
{
throw new RuntimeException("Array is empty");
}
int num = array[--size];
if (array.length > 4 * size)
{
int[] newArray = new int[array.length / 2];
System.arraycopy(array, 0, newArray, 0, size);
array = newArray;
}
return num;
}
public int get(int index)
{
if (index < 0 || index >= size)
{
throw new IndexOutOfBoundsException("Illegal index");
}
return array[index];
}
public int indexOf(int key)
{
for (int i = 0; i < size; i++)
{
if (array[i] == key)
{
return i;
}
}
return -1;
}
public void add(int index, int num)
{
if (index < 0 || index > size)
{
throw new IndexOutOfBoundsException("Illegal index");
}
if (size == array.length)
{
int[] newArray = new int[array.length * 2];
System.arraycopy(array, 0, newArray, 0, index);
newArray[index] = num;
System.arraycopy(array, index, newArray, index + 1, size - index);
array = newArray;
}
else
{
System.arraycopy(array, index, array, index + 1, size - index);
array[index] = num;
}
size++;
}
public int remove(int index)
{
if (index < 0 || index >= size)
{
throw new IndexOutOfBoundsException("Illegal index");
}
int num = array[index];
System.arraycopy(array, index + 1, array, index, size - index - 1);
size--;
if (array.length > 4 * size)
{
int[] newArray = new int[array.length / 2];
System.arraycopy(array, 0, newArray, 0, size);
array = newArray;
}
return num;
}
public boolean isEmpty()
{
return size == 0;
}
/**
* Returns a string representation of the array in the format of comma-separated values enclosed in
square brackets.
*
* @return a string representation of the array.
*/
public String toString()
{
if (size == 0)
{
return "[]";
}
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < size - 1; i++)
{
sb.append(arr[i]).append(", ");
}
sb.append(arr[size - 1]).append("]");
return sb.toString();
}
/**
* Compares this DynamicArray object with the specified object for equality.
*
* @param obj the object to compare to.
* @return true if the specified object is equal to this DynamicArray object, false otherwise.
*/
public boolean equals(DynamicArray obj)
{
if (obj == null || getClass() != obj.getClass() || size != obj.size)
{
return false;
}
for (int i = 0; i < size; i++)
{
if (arr[i] != obj.arr[i])
{
return false;
}
}
return true;
}
}
Ad

More Related Content

Similar to java I am trying to run my code but it is not letting me .pdf (20)

Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
TaseerRao
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
Rajeev Uppala
 
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdfJava R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
kamalabhushanamnokki
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
abdullah619
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
SoftNutx
 
java detailed aadvanced jaavaaaaa2-3.ppt
java detailed aadvanced jaavaaaaa2-3.pptjava detailed aadvanced jaavaaaaa2-3.ppt
java detailed aadvanced jaavaaaaa2-3.ppt
ndillisri4
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
object oriented programing in python and pip
object oriented programing in python and pipobject oriented programing in python and pip
object oriented programing in python and pip
LakshmiMarineni
 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
SARAVANAN GOPALAKRISHNAN
 
Array
ArrayArray
Array
PRN USM
 
Java collections
Java collectionsJava collections
Java collections
Hamid Ghorbani
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
RithwikRanjan
 
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptxM251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
smartashammari
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
Shahzad
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
shafat6712
 
Lec2
Lec2Lec2
Lec2
Anjneya Varshney
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
Liza Abello
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
ManojKandhasamy1
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
TaseerRao
 
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdfJava R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
Java R20 - UNIT-3.pdf Java R20 - UNIT-3.pdf
kamalabhushanamnokki
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
Arthik Daniel
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
SoftNutx
 
java detailed aadvanced jaavaaaaa2-3.ppt
java detailed aadvanced jaavaaaaa2-3.pptjava detailed aadvanced jaavaaaaa2-3.ppt
java detailed aadvanced jaavaaaaa2-3.ppt
ndillisri4
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answeredU-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
object oriented programing in python and pip
object oriented programing in python and pipobject oriented programing in python and pip
object oriented programing in python and pip
LakshmiMarineni
 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
 
A2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.pptA2003822018_21789_17_2018_09. ArrayList.ppt
A2003822018_21789_17_2018_09. ArrayList.ppt
RithwikRanjan
 
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptxM251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
M251_Meeting_ jAVAAAAAAAAAAAAAAAAAA.pptx
smartashammari
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
Shahzad
 

More from adinathassociates (20)

It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdf
adinathassociates
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
adinathassociates
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdf
adinathassociates
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdf
adinathassociates
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdf
adinathassociates
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdf
adinathassociates
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
adinathassociates
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdf
adinathassociates
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdf
adinathassociates
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
adinathassociates
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
adinathassociates
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdf
adinathassociates
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
adinathassociates
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdf
adinathassociates
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdf
adinathassociates
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
adinathassociates
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
adinathassociates
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
adinathassociates
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdf
adinathassociates
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdf
adinathassociates
 
It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdf
adinathassociates
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
adinathassociates
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdf
adinathassociates
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdf
adinathassociates
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdf
adinathassociates
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdf
adinathassociates
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
adinathassociates
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdf
adinathassociates
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdf
adinathassociates
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
adinathassociates
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
adinathassociates
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdf
adinathassociates
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
adinathassociates
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdf
adinathassociates
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdf
adinathassociates
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
adinathassociates
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
adinathassociates
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
adinathassociates
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdf
adinathassociates
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdf
adinathassociates
 
Ad

Recently uploaded (20)

What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Ad

java I am trying to run my code but it is not letting me .pdf

  • 1. java I am trying to run my code but it is not letting me i dont know what i should do or fix. Thank you so much for your help. This is the problem and my code will be on the bottom. Problem #1 and Only Dynamic Array of Integers Class Create a class named DynamicArray that will have convenient functionality similar to JavaScripts Array object and Javas ArrayList class. The class allows to store array of integers that can grow and shrink as needed, search for values, remove elements, etc. You are not allowed to use ArrayList object as well as any methods from java.util.Arrays class. Please see the list of required features and methods below. private int array[] You MUST store the data internally in a regular partially-filled array of integers. Please DO NOT USE ArrayList. The size of the allocated array is its capacity and will be discussed below. private int size. This variable stores the number of occupied elements in the array. Set to 0 in the constructor. Constructor with parameter. The parameter defines the capacity (length) of initial array. Allocates array of given capacity (length), sets size field to 0. In case the parameter given to constructor is 0 or negative, IllegalArgumentException is being thrown. No-argument constructor. Allocates array of length 3, assigns it to the array field, sets size field to 0. Copy constructor. The constructor takes an object of type DynamicArray as a parameter and copies it into the object it creates. The constructor throws IllegalArgumentException if the object that was passed to copy from is null. int getSize() returns the number of occupied elements in the array. int getCapacity() returns the actual size (length) of the partially-filled array int [] getArray() accessor returns the entire partially-filled array. Make sure you DO NOT return the private array field, make a copy of it. int [] toArray() accessor returns an occupied part of the partially-filled array. Make sure you DO NOT return the private array field. Instead, allocate memory for the new array, copy the occupied portion of the field into that new object, and return the new array. public void push(int num) adds a new element to the end of the array and increments the size field. If the array is full, you need to increase the capacity of the array: Create a new array with the size equal to double the capacity of the original one. Copy all the elements from the array field to the new array. Add the new element to the end of the new array. Use new array as an array field. Make sure your method works well when new elements are added to an empty DynamicArray. public int pop() throws RuntimeException removes the last element of the array and returns it. Decrements the size field. If the array is empty a RuntimeException with the message Array is empty must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger than the number of occupied elements (size), it is time to shrink the array:
  • 2. Create a new array with the size equal to half of the capacity of the original one. Copy all the elements from the array field to the new array. Use new array as an array field. int get(int index) throws IndexOutOfBoundsException returns element of the array with the requested index. If the index provided is too large or negative, the IndexOutOfBoundsException is thrown with the message Illegal index. int indexOf(int key) returns the index of the first occurrence of the given number. Returns -1 when the number is not found. void add(int index, int num) throws IndexOutOfBoundsException adds a new element (passed as parameter num) to the location of the array specified by index parameter. If the index is larger than size of the array or less than 0, IndexOutOfBoundsException is thrown. When adding the element into the middle of the array, youll have to shift all the elements to the right to make room for the new one. If the array is full and there is no room for a new element, the array must be doubled in size. Please follow the steps listed in the push() method description to double the capacity of the array. int remove ( int index) throws IndexOutOfBoundsException removes and returns the value of an element at the specified position in this array. When the element is removed from the middle of the array, all the elements must be shifted to close the gap created by removed element. If the index value passed into the method is more or equal to the size or less than 0 the IndexOutOfBoundsException must be thrown. At this point check the capacity of the array. If the capacity is 4 times larger than the number of occupied elements (size), it is time to shrink the array. boolean isEmpty() returns true if the size of the array is 0. String toString() returns an array as a string of comma-separated values. Sample: [1, 2, 3, 4] boolean equals(DynamicArray obj) compares two objects (this one and the one passed as parameter) element-by-element and determines if they are exactly the same. The capacity of the two objects is not being compared and can be different. MY CODE; public class DynamicArray { private int Array[]; private int size; // Constructor with parameter public DynamicArray(int capacity) { if (capacity <= 0) { throw new IllegalArgumentException("Invalid capacity: " + capacity); } array = new int[capacity]; size = 0; }
  • 3. // No-argument constructor public DynamicArray() { this(3); } // Copy constructor public DynamicArray(DynamicArray other) { if (other == null) { throw new IllegalArgumentException("Cannot copy from null object"); } array = new int[other.array.length]; System.arraycopy(other.array, 0, array, 0, other.size); size = other.size; } public int getSize() { return size; } public int getCapacity() { return array.length; } public int[] getArray() { return Arrays.copyOf(Array, Array.length); } public int[] toArray() { return Arrays.copyOf(array, size); } public void push(int num) { if (size == array.length) { int[] newArray = new int[array.length * 2]; System.arraycopy(array, 0, newArray, 0, array.length); array = newArray; } array[size++] = num; }
  • 4. public int pop() { if (size == 0) { throw new RuntimeException("Array is empty"); } int num = array[--size]; if (array.length > 4 * size) { int[] newArray = new int[array.length / 2]; System.arraycopy(array, 0, newArray, 0, size); array = newArray; } return num; } public int get(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException("Illegal index"); } return array[index]; } public int indexOf(int key) { for (int i = 0; i < size; i++) { if (array[i] == key) { return i; } } return -1; } public void add(int index, int num) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException("Illegal index"); } if (size == array.length) {
  • 5. int[] newArray = new int[array.length * 2]; System.arraycopy(array, 0, newArray, 0, index); newArray[index] = num; System.arraycopy(array, index, newArray, index + 1, size - index); array = newArray; } else { System.arraycopy(array, index, array, index + 1, size - index); array[index] = num; } size++; } public int remove(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException("Illegal index"); } int num = array[index]; System.arraycopy(array, index + 1, array, index, size - index - 1); size--; if (array.length > 4 * size) { int[] newArray = new int[array.length / 2]; System.arraycopy(array, 0, newArray, 0, size); array = newArray; } return num; } public boolean isEmpty() { return size == 0; } /** * Returns a string representation of the array in the format of comma-separated values enclosed in square brackets. * * @return a string representation of the array. */ public String toString() {
  • 6. if (size == 0) { return "[]"; } StringBuilder sb = new StringBuilder("["); for (int i = 0; i < size - 1; i++) { sb.append(arr[i]).append(", "); } sb.append(arr[size - 1]).append("]"); return sb.toString(); } /** * Compares this DynamicArray object with the specified object for equality. * * @param obj the object to compare to. * @return true if the specified object is equal to this DynamicArray object, false otherwise. */ public boolean equals(DynamicArray obj) { if (obj == null || getClass() != obj.getClass() || size != obj.size) { return false; } for (int i = 0; i < size; i++) { if (arr[i] != obj.arr[i]) { return false; } } return true; } }
  翻译: