Basically I have to fill in the party\'s that need filling from this code below
ID: 3883261 • Letter: B
Question
Basically I have to fill in the party's that need filling from this code below in order to make it work how it says on the rubricpublic class IntArrayList {
private int maxSize; private int listSize; private int curr; private int [] listArray;
public IntArrayList(int size) { maxSize = size; listSize = 0; curr = 0; listArray = new int[maxSize]; }
public IntArrayList( ) { maxSize = 100; listSize = 0; curr = 0; listArray = new int[maxSize]; }
public void clear() { listSize = 0; curr = 0; }
// Insert an element at the current location. // item: The element to be inserted public void insert(int num) { /* * * FILL THIS PART * */ }
// Append an element at the end of the list. // item: The element to be appended. public void append(int num) { /* * * FILL THIS PART * */ }
// Remove and return the current element. // Return: the element that was removed. public int remove() { /* * * FILL THIS PART * */ }
// Return: The current element. public int getValue() { /* * * FILL THIS PART * */ }
public void printAll() { /* * * FILL THIS PART * */ }
// Set current position. // pos: The position to make current. public void moveToPos(int pos) { /* * * FILL THIS PART * */ }
// Set curr to 0 (front) public void moveToStart() { curr = 0; }
// Set currr to listSize (end) public void moveToEnd() { curr = listSize; }
// move curr to the prev position public void prev() { if (curr > 0) curr--; }
// move curr to the next position public void next() { if (curr < listSize) curr++; }
// return the length of List public int length() { return listSize; }
// return curr position public int currPos() { return curr; }
public static void main(String[] args) { // Testing IntArrayList IntArrayList lst = new IntArrayList(10); lst.printAll(); lst.insert(1); lst.insert(2); lst.insert(3); lst.insert(4); lst.insert(5); lst.insert(6); lst.printAll(); lst.moveToEnd(); lst.insert(10); lst.printAll(); lst.moveToStart(); lst.insert(100); lst.printAll(); lst.moveToPos(4); System.out.println("array[4] = " + lst.getValue()); lst.clear(); lst.printAll();
lst.insert(12); lst.append(0); lst.append(1); lst.append(2); lst.insert(22); lst.moveToPos(1); lst.remove();
lst.printAll(); } }
Due: Tuesday, Sep. 15,2015 11:59 PM for 100 points Early Bonus: Monday, Sep. 14h,201511:59 PM for a 10 point bonus Submission Instructions: Submissions should be made on Blackboard. Upload your java files only No email submission is allowed. 1. Complete IntArrayList.java file. Grading Rubric Style o (20 points) Code readability (proper indentation, appropriate variable names, etc) 0 (20 points) Documentation (programmer names, homework # and date; program and functions have brief comments describing their purpose, inline comments used as necessary) Correctness o (10 points) insert (no partial credit will be given o (10 points) append (no partial credit will be given) o (10 points) remove (no partial credit will be given o (10 points) moveToPos (no partial credit will be given) o (10 points) getValue (no partial credit will be given) o (10 points) printAll (no partial credit will be given) o(-40 points) Non-Compilable Code
Explanation / Answer
Here is your completed java program:
IntArrayList Java:
public class IntArrayList {
private int maxSize;
private int listSize;
private int curr;
private int [] listArray;
public IntArrayList(int size) {
maxSize = size;
listSize = 0;
curr = 0;
listArray = new int[maxSize];
}
public IntArrayList( ) {
maxSize = 100;
listSize = 0;
curr = 0;
listArray = new int[maxSize];
}
public void clear() {
listSize = 0;
curr = 0;
}
// Insert an element at the current location.
// item: The element to be inserted
public void insert(int num) {
listArray[curr]=num;
if(curr==listSize)
listSize++;
curr++;
}
// Append an element at the end of the list.
// item: The element to be appended.
public void append(int num) {
listArray[listSize]=num;
listSize++;
}
// Remove and return the current element.
// Return: the element that was removed.
public int remove() {
int n;
n=listArray[curr];
for(int i=curr;i<listSize;i++)
{
if(i!=listSize)
{
listArray[i]=listArray[i+1];
}
}
listSize-=1;
/*int[] temp=new int[listArray.length];
for(int i=0;i<listArray.length-1;)
{
if(i==curr)
continue;
else
{
temp[i]=listArray[i];
i++;
}
}
listArray=temp;*/
return n;
}
// Return: The current element.
public int getValue() {
return listArray[curr];
}
public void printAll() {
for(int i=0;i<listSize;i++)
System.out.println(listArray[i]+" ");
}
// Set current position.
// pos: The position to make current.
public void moveToPos(int pos) {
curr=pos-1;
}
// Set curr to 0 (front)
public void moveToStart() {
curr = 0;
}
// Set currr to listSize (end)
public void moveToEnd() {
curr = listSize;
}
// move curr to the prev position
public void prev() {
if (curr > 0)
curr--;
}
// move curr to the next position
public void next() {
if (curr < listSize)
curr++;
}
// return the length of List
public int length() {
return listSize;
}
// return curr position
public int currPos() {
return curr;
}
public static void main(String[] args) {
// Testing IntArrayList
IntArrayList lst = new IntArrayList(10);
lst.printAll();
lst.insert(1);
lst.insert(2);
lst.insert(3);
lst.insert(4);
lst.insert(5);
lst.insert(6);
lst.printAll();
lst.moveToEnd();
lst.insert(10);
lst.printAll();
lst.moveToStart();
lst.insert(100);
lst.printAll();
lst.moveToPos(4);
System.out.println("array[4] = " + lst.getValue());
lst.clear();
lst.printAll();
lst.insert(12);
lst.append(0);
lst.append(1);
lst.append(2);
lst.insert(22);
lst.moveToPos(1);
lst.remove();
lst.printAll();
}
}
I hope this solves your problem
Comment if you have any problem in above code
And please give it a thumbs up if it solved your problem :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.