JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on


Please find the answer below, I have mentioned all the details in the comments:
SortedList.java
import java.util.ArrayList;
public class SortedList {
//private array list to store the elements
private ArrayList<Integer> list;
//constructor
SortedList(){
list = new ArrayList<>();
}
//to add the value to the list
public void add(int value){
//get the current last element
int last = list.size();
//add the new value
list.add(value);
//shift all the values till the correct position
while (last>0 && value < list.get(last - 1)){
list.set(last,list.get(last-1));
last--;
}
//set the value at final position
list.set(last,value);
}
//to remove the element from the list
public int remove(int index){
return list.remove(index);
}
//to print the list
public String toString(){
return list.toString();
}
//to check of the list contains the value
public boolean contains(int value){
return list.contains(value);
}
//to get the value from the index
public int get(int index){
return list.get(index);
}
//to clear the list
public void clear(){
list.clear();
}
//get hte index of the particular value in the list, it would return -1 if value is not present
public int indexOf(int value){
return list.indexOf(value);
}
//check if list is empty or not
public boolean isEmpty(){
return list.isEmpty();
}
//main method
public static void main(String[] args) {
//create new list
SortedList list = new SortedList();
//check for the empty or not
System.out.println("List is Empty?: " + list.isEmpty());
//add some values
list.add(5);
list.add(3);
list.add(7);
//check the list
System.out.println("List: " + list.toString());
//add one more value
list.add(1);
//check the list content
System.out.println("List: " + list.toString());
//remove element from the list by giving the index
System.out.println("Removed from list: " + list.remove(1));
System.out.println("List: " + list.toString());
//cehck the value at index
System.out.println("Value at index 1 from list: " + list.get(1));
System.out.println("List: " + list.toString());
//check for the contains method
System.out.println("List contains 5?: " + list.contains(5));
System.out.println("List contains 9?: " + list.contains(9));
//check the index of the value
System.out.println("Index of 5?: " + list.indexOf(5));
System.out.println("Index of 9?: " + list.indexOf(9));
System.out.println("List is Empty?: " + list.isEmpty());
System.out.println("Clearing the list");
//clear the list
list.clear();
System.out.println("List: " + list.toString());
System.out.println("List is Empty?: " + list.isEmpty());
}
}
Output:
![C: Program Files Java jdk1.8.0_151binljava List is Empty?: true ist: 13, 5, 71 List: [1, 3, 5, 7] Removed from list: 3 List](http://img.homeworklib.com/images/390af3bc-d699-4adb-be93-b75bd65426d2.png?x-oss-process=image/resize,w_560)
JAVA (implementing a collection class) write a completed program (must include MAIN) and straight to the output based on 4. Based on the implementation of ArrayIntlist or ArrayList, write a class Sor...
JAVA (implementing a collection class) write a completed program
using ArrayIntList and Client
ArrayIntList.java
public class ArrayIntList {
private int[] elementData; // list of integers
private int size; // current number of elements in the list
public static final int DEFAULT_CAPACITY = 100;
// pre : capacity >= 0
// post: constructs an empty list with the given capacity
public ArrayIntList(int capacity) {
elementData = new int[capacity];
size = 0;
}
// post: constructs an empty list of default capacity...
I am currently using eclipse to write in java.
A snapshot of the output would be greatly appreciated to verify
that the program is indeed working. Thanks in advance for both your
time and effort.
Here is the previous exercise code:
/////////////////////////////////////////////////////Main
/*******************************************
* Week 5 lab - exercise 1 and exercise 2: *
* ArrayList class with search algorithms *
********************************************/
import java.util.*;
/**
* Class to test sequential search, sorted search, and binary search
algorithms
* implemented in...
iii.print out the arraylist iv.reverse all the elements v.print
out this arraylist vi.make a clone of the arraylist
vii.remove all the elements at any odd index of the original
arraylist (not the cloned one)
viii.print out the original arraylist ix.reverse the cloned
arraylist x.print out the cloned arraylist (this arraylist should
still contain the original sequence of elements in order)
xi.merge the cloned arraylist to the original arraylist (please
think about what happens and draw a diagram for yourself to...
java
Create the following classes: DatabaseType: an interface that contains one method 1. Comparator getComparatorByTrait(String trait) where Comparator is an interface in java.util. Database: a class that limits the types it can store to DatabaseTypes. The database will store the data in nodes, just like a linked list. The database will also let the user create an index for the database. An index is a sorted array (or in our case, a sorted ArrayList) of the data so that searches...
JAVA Write a program which will read a text file into an ArrayList of Strings. Note that the given data file (i.e., “sortedStrings.txt”) contains the words already sorted for your convenience. • Read a search key word (i.e., string) from the keyboard and use sequential and binary searches to check to see if the string is present as the instance of ArraryList. • Refer to “SearchInt.java” (given in “SearchString.zip”) and the following UML diagram for the details of required program...
JAVA (advanced data structures) write a completed program using
HashIntSet and HashMain
include the method in the main if possible. those are just the
sample HashIntSet and HashMain (don't have to be the same but
follow the Q requirement. thanks
HashIntSet.java
public class HashIntSet {
private static final double MAX_LOAD_FACTOR = 0.75;
private HashEntry[] elementData;
private int size;
// Constructs an empty set.
public HashIntSet() {
elementData = new HashEntry[10];
size = 0;
}
// Adds the given element to...
Write a generic array list class. Task Description Your goal for this lab is to write a generic ArrayList class similar to the one in the given lecture notes on array lists. The ArrayList Class The public constructors and methods required for the ArrayList class are listed here. The type E is the generic type of an element of the list. ArrayList() Construct an empty ArrayList object. int size() Return the size (number of items) in this ArrayList. boolean isEmpty()...
Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...
JAVA write a completed program (must include MAIN) and straight
to the output on Q1
e following exercises is a method to be added to the ArrayIntlist class from this chapter Each of the a method called lastIndexof that accepts an integer as a parameter and returns the index in the list of ce of that value, or -1 if the value is not found in the list. For example, if the list stores 1 the 40], then the last...
Please help with Java array list:
import java.util.ArrayList;
public class ListUpdate {
/**
* Does a linear search through the ArrayList list, returning the
index of the first occurrence of
* valToFind.
*
* Starting from index 0, check each element in list and return the
index of the first element
* that matches valToFind.
*
* @param valToFind The int value to search for.
* @param list The ArrayList of Integers to search in.
* @return The index of...