Question: This might seem like a long question, but its not. Here is the previous assignment question that we were supposed to do and I have
This might seem like a long question, but its not. Here is the previous assignment question that we were supposed to do and I have the code solution for this assignment too below that:
Previous Assignment Question:




Here is the code for this assignment. Also, i didn't include the JUnit code for it although i do have it, and the following code passed all the tests:
package assign3;
public class OrderedList {
private int[] list; /ot using ArrayLists
private int count;
public OrderedList(int size)
{ if(size
size = 2;
list = new int[size];
count = 0; }
public int size()
{ return list.length; //return the max number of values that can be currently stored. }
public int numEntries()
{ return count; //return the number of integers currently stored in the array } // if there are no values, then show 0, so that the range is from 0 to the size of array
private void insertAtLocation(int location, int value)
{ for(int index = count; index > location; --index)
{ list[index] = list[index-1]; //moving the other values "down" so there is room for new value. }
list[location] = value; //insert at designated location }
public void insert(int number)
{ boolean inserted = false;
if(count == size()) //if the array is full do not insert the value.
return;
for(int index = 0 ; index
return; //return without adding; means that it will not go through the rest of the lines.
else if( list[index] > number)
{ insertAtLocation(index, number);
inserted = true; //making sure not to break from inside the loop }
}
if(!inserted) //if still not inserted in the middle, then that means it belongs in the end.
list[count] = number;
count++; //keep on incrementing count }
private void deleteAtLocation(int location)
{ for(int index = location; index
{ list[index] = list[index+1]; }
}
public void delete(int integer)
{ boolean deleteFlag = false; //using a flag to avoid returning or breaking from the loop
for(int index = 0; index
{ if(list[index] == integer) //if it matches the value then delete it
{ deleteAtLocation(index); //delete
count--; //shift up the cells deleteFlag = true; //making sure that I don't break or return from the loop }
}
}
public String toString()
{ String string = "";
if(count == 0)
return string; //return empty
else
{ string += list[0];
for(int index = 1; index
string += " "+ list[index]; //making sure that there is no space after the last integer.
return string; }
}
}
And here is the NEW ASSIGNMENT WHICH I NEED ANSWER FOR:


As you can see, this new assignment is not that different from the previous assignment, since the new assignment kind of requires Nodes and Linked list and just different implementation from the first assignment. That's the reason I gave you guys the previous assignment, so you can change the code accordingly and save your time.
As for the style and documentation, please don't return or break from inside a loop. Also, please add lots of comments so that I know what you're doing.
Package name should be "assign6"
Required package name: assign3 Required class name: OrderedList File to submit Part 1: OrderedListTest.java File to submit Part 2: OrderedList.java Part 1 Create a Junit test file for the following class. Important you are not to create the Java file for this part of the assignment, but to just create the Junit test file, OrderedListTest java. OrderedList - ist int - count: int + OrderedList(int) + size ): int + numEntries): int + insert (int): void + delete (int): void +toString0: String Method descriptions and test conditions You may have several test methods for each. 1. OrderedList (int) create an array of the size indicated by the parameter if the parameter is less than 2, create an array of size 2 a. b. Ideas for Testing: a. instantiate an array and check to see if it has the correct size b. instantiate an array and check to see if there are no entries in the array c. instantiate an array with a size of 2 and check if it has the correct size d. repeat the above test for a size of 1 and 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
