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 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"}
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...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
I am trying to create a function in JAVA that takes in an ArrayList and sorts...
I am trying to create a function in JAVA that takes in an ArrayList and sorts the values by their distance in miles in increasing order. So the closest (or lowest) value would be first. It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. The code for the main class is not necessary. I am only really asking for the...
I am trying to create a method in JAVA that takes in an ArrayList and sorts...
I am trying to create a method in JAVA that takes in an ArrayList and sorts it by the requested "amenities" that a property has. So if someone wants a "pool" and "gym" it would show all members of the array that contain a "pool" and "gym". It does not need to output the values in anyway, but it should return them so they can be output elsewhere. Please try to use the stub class below. You can edit it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT