Question

In: Computer Science

In java, please Create an ArrayListReview class with one data field of ArrayList with the generic...

In java, please

  1. Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)

  2. Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)

  3. Implement mergeSort using a list and recursion. (2 points)

  4. Write the main method to test your program and use System.nanoTime() to find out the speed of each step of your program. (1 point)

Solutions

Expert Solution

  1. Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)

  2. Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)

Main.java

import java.util.ArrayList;

//Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)
class ArrayListReview<T>
{
// An object of type T is declared
ArrayList<T> arrayList=new ArrayList<>();
//Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)
  
ArrayListReview(T obj,int index) { this.arrayList .add(index, obj); } // constructor
public T getObject(int index) { return this.arrayList.get(index); }
}

// Driver class to test above
class Main
{
public static void main (String[] args)
{
// passing instance of Integer type to generic class ArrayListReview
ArrayListReview <Integer> arrayListReviewObj = new ArrayListReview<Integer>(15,0);
System.out.println("Integer type : "+arrayListReviewObj.getObject(0));

//passing instance of instance of String type to generic class ArrayListReview
ArrayListReview <String> arrayListReviewObj1 = new ArrayListReview<String>("This is string",0);
System.out.println("String type : "+arrayListReviewObj1.getObject(0));

}
}

Output


Related Solutions

in java please: Create an ArrayListReview class with one data field of ArrayList and one with...
in java please: Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with the generic type passed to the class. (2 point) Create a constructor that populate an array list and the LinkedList filled with the generic type through inserting new elements into the specified location index-i in the list. (2 points)
Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with the...
Create an ArrayListReview class with one data field of ArrayList and one with LinkedList with the generic type passed to the class. (2 point) 2. Create a constructor that populate an array list and the LinkedList filled with the generic type through inserting new elements into the specified location index-i in the list. (2 points) 3. You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing information for...
IN Java please 1. Define a class called ListExercise containing one data field: a list of...
IN Java please 1. Define a class called ListExercise containing one data field: a list of integer. Create two constructor methods, one accessor(getter) method and one mutator(setter) method for the ListExercise class. 2. Implement a reverse(int[] a) method to reverse the elements in the list. For example, reverse(Arrays.asList(new int[ ]{1,2,3})) should return {3,2,1}. 3. Implement a swapValue(List a, int i, int j) to swap the values in index i and j. 4. Implement a pickMost(int[] a) method to pick the...
Create a generic method to print objects in java. Include a tester class.
Create a generic method to print objects in java. Include a tester class.
IN JAVA PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String and returns a copy of that ArrayList with no duplicates. The relative ordering of elements in the new ArrayList should be the same. Sample Input: {"qwerty", "asdfgh", "qwer", "123", "qwerty", "123", "zxcvbn", "asdfgh"} Sample Output: {"qwerty", "asdfgh", "qwer", "123", "zxcvbn"}
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist to store/ add product in stock 3. Product must have name, code number and quantity in stock 4. Print list of the products and their stock quantity 5. Search products based on their name 6. Remove product based on their code number 7. Sell product and deduct quantity from stock 8. Stock Class contains methods of search product, add product and check quantity of...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist...
Grocery Store using Java Arraylist Requirements: 1. Need Product Class and Stock Class 2. Use arraylist to store/ add product in stock 3. Product must have name, code number and quantity in stock 4. Print list of the products and their stock quantity 5. Search products based on their name 6. Remove product based on their code number 7. Sell product and deduct quantity from stock 8. Stock Class contains methods of search product, add product and check quantity of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT