Create an ExtArrayList class by extending the ArrayListE> class to include the following methods and estimate the run-time complexity of each method.
1. public ExtArrayList append(ExtArrayList ea)
// appends the values in ea to the end of this ExtArrayList and returns the new ExtArrayList
//example: this: {1,2,3} parameter : {4,5}, result {1,2,3,4,5} 2. public boolean consecutivePair(E e1, E e2)
// checks if this ExtArrayList has two consecutive elements that are equal to e1 and e2 from the
//beginning to the end of the list in that order and returns true, otherwise returns false. You can assume the existence of an appropriately defined equals() method.
// you need to handle errors for different situations.
Create an ExtLinkedList class by extending the LinkedList class to include the following methods and estimate the run-time complexity of each method.
3. public ExtLinkedList evenList()
// gets the elements E in locations 0,2,4,6,… of this list and puts them in a new ExtLinkedList in that order and returns it
// make sure to handle errors 4. public ExtLinkedList intsersect (ExtLinkedList eli)
// picks out elements that are common to this ExtLinkedList and eli // and returns them in the form of a new ExtLinkedList
// once again, you can use equals () method
// the new list should not have duplicate elements // handle errors or exceptional situations appropriately.
// example: this: {1,3,4,4}, parameter : {1,4,5,7} then return {1,4}
The code for the first question related to Create an ExtArrayList class by extending the ArrayListE> class is as follow
import java.util.ArrayList;
import java.util.Arrays;
public class ExtArrayList<E> extends ArrayList {
/**
* appending new list to end of the list and return new
* @param extArrayList
* @return
*/
public ExtArrayList append(ExtArrayList extArrayList) {
// runtime will the O(n) as it will add all data from both array
// and n will the sum of size of both array
if(extArrayList==null){
throw new NullPointerException(" Values of the array should not be null");
}else{
ExtArrayList elements = this;
elements.addAll(extArrayList);
return elements;
}
}
/**
* function to check two consecutive elements
*
* @param element1
* @param element2
* @return
*/
public boolean consecutivePair(E element1, E element2) {
/*
running time of this function is max O(N)
and min is O(1) if first two consecutive
elements are present
*/
if (element1 == null || element2 == null){
throw new NullPointerException("value of e1 or e1 cannot be null");
}
for (int i = 0; i < this.size(); i++) {
if (this.get(i).equals(element1)) {
if (i < this.size() - 1) {
if (this.get(i + 1).equals(element2)) {
return true;
}
}
}
}
return false;
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
public static void main(String args[]){
//creating object ele1 of class
ExtArrayList<Integer> elem1 = new ExtArrayList<>();
// Adding the elemets to object created
elem1.addAll(Arrays.asList(3, 5, 6, 6, 8));
//creating object ele2 of class
ExtArrayList<Integer> elem2 = new ExtArrayList<>();
// Adding the elemets to object created
elem2.addAll(Arrays.asList(5, 7, 2, 7, 3));
//combining two ExtArraylist using append method
ExtArrayList<Integer> merged_array = elem1.append(elem2);
System.out.println("Merged Array :" + merged_array);
System.out.print("checking consecutive element (7,3) in ele2 object ");
System.out.println(elem1.consecutivePair(7, 3));
}
}
// output
Merged Array :[3, 5, 6, 6, 8, 5, 7, 2, 7, 3]
checking consecutive element (7,3) in ele2 object true
The time complexity is written as a comment in function only.
I hope you understand the code and got the answer.
Kindly ask the question of creating an ExtLinkedList class by extending the LinkedList class to include the following methods, as it is another question.
I hope you understand it and Thank you:):)
Create an ExtArrayList class by extending the ArrayListE> class to include the following methods and estimate...
COMP Help (Java): Can someone please help me with this problem! Someone answered it but it was wrong. 1. Create an ExtArrayList<E> class by extending the ArrayListE> class to include the following methods and estimate the run-time complexity of each method. public ExtArrayList<E> append(ExtArrayList<E> ea) // appends the values in ea to the end of this ExtArrayList and returns the new ExtArrayList //example: this: {1,2,3} parameter : {4,5}, result {1,2,3,4,5} public boolean consecutivePair(E e1, E e2) // checks if this...
JAVA Write Java code for extending the LinkedList class of java.util.* to ExtLinkedList that would include the following method: public ExtLinkedList firstHalfList() which returns the first half of the list. In other words, if you have a ExtLinkedList of size 5, for example, the method firstHalfList should return the list with the first two nodes. If it is a list of size 6, it should return the list with the first three nodes. The original list should not be modified....
Write a JAVA code to do the following: create a class and add methods to count the number of primitive fields, number of methods with primitive return types, a method that will also return the number of primitive in a given parameter. they are: public int getNumberOfPrimitiveMethods(Class host) public int getNumberOfPrimitiveFields(Class host) public int getNumberOfPrimitiveParameters(Method host) also public int getNumberOfPrivateMethods (Class host) public int getNumberOfPublicMethods (Class host)
Please make sure the code works perfectly and is accurate. This is high-stake assignment. I will rate highly, thank you very much for saving my life. Question: Create a Java program that extends the LinkedList<E> class of java.util.* to ExtLinkedList<E> that would have these methods: public class ExtLinkedList<E> extends LinkedList<E> { public ExtLinkedList<E>subList() { .... (stuff goes here) } } which returns the values stored at index 0,3,6,9, … of the list. If given an empty list it should simply...
Create a LIFO class with following methods in java - public LifoList() The default constructor for LifoList class which will initialize your class variables maxSize to 0 and the int array to null. public LifoList(int maxSize) The constructor for LifoList class which takes the int input maxSize to initialize the size of the array. You should NOT reinitialize the array elsewhere. For example, creating an object as new LifoList(5) should create a LifoList whose maximum size is 5. If the...
JAVA HELP (ARRAYS)
Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...
Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet object holds integers in the range 0-100 Represented by an array of booleans, such that array element a[i] is set to true if integer i is in the set, and false otherwise Create these constructors and methods for the class IntegerSet() public IntegerSet union(IntegerSet iSet) public IntegerSet intersection(IntegerSet iSet) public IntegerSet insertElement(int data) public IntegerSet deleteElement(int data) public boolean isEqualTo(IntegerSet iSet) public String toString()...
Create a new Java Application that test MyStack by having the following methods in main class: 1. A method to generate a number of element between two given values and save them in a stack 2. A method to print a stack (10 elements per line). The original stack should remain as is after the print 3. A method to exchange the first element and the last element in a stack 4. A Boolean method to search for a value...
JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...
Create a class named Program10. Your program should have the following 4 methods (other helper methods are allowed, but these four methods must be implemented as specified). You need to define a global scanner object and only use it inside the main method and the getValues method, since other methods do not get any values from the input. getValues: This method does not have any input parameter and returns an array of integers. This method prompts the user with a...