Need some help with this java problem, thanks!![Lab 6 dock Word File Home Insert Draw Design Layout References Mailings Review View Q lell me what you want to do How to Submit Please submit your answers to the lab instructor once you have completed. Failure to submit will result in a ZERO FOR THIS LAB NOEXCEPTIONS. 1. Write a program that prints out the lists after the following methods are called. a. Method miruroagon akes an Ar 5L or integers as a parameler. The method novcs the minimum valuc in the list to the front, oth prcscrving thc ordcr crwisc of the elements. For example, if a variable called list stores the following values: 4. 7,9, 2. 7, 7, 5, 3, 5, 1, 7, 8, 6, 71 and you make Lhis call: list. it should store the following values after the call: Li,4, 7, 9, 2,7, 7, 5, 3, 5. 7, 8, 6. 71. You may assume that the list stores at least one value. After the call print the list, b. Method ti terEange: accepts an ArrayList of integers and two integer values min and max as parameters and removes all elements whose values are in lhe range min through max (inclusive) from the list. For example, if a variable called list stores the values: [1. 4, 7, 9. 2, 7, 7, 5, 3, 5, 7, 8, 6, 71 The call of hould remo ove all values between 5 and is 7, therefore it should change the list to store [1,4, 9, 2, 3, R]. You may assume that the list is not null. Aner Lhe call print the list. c. Method intersec accepts two sorted array lists of integers as parameters and relurns a new list that contains only the elements lhal are found in b lists. For olh example, if lists named li and list2 ally store: [1, 4, 8, 9. 11, 15, 17, 28, 41, 59 [4, 7, 11, 17, 19, 20, 23, 28, 37, 59, 81] en the ca eturns the lis L2 L4, 11, 17, 28, 59 Print the list that is returned by thi method Page 1 of 1 334 words Dx Paull ojo Share 89%](http://img.homeworklib.com/questions/0d3863c0-20cc-11ec-996f-11182b663c40.png?x-oss-process=image/resize,w_560)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class ListUtil {
public List<Integer>
minToFront(List<Integer> list) {
List<Integer> copy = new
ArrayList<Integer>(list);
int min =
Collections.min(copy);
copy.remove(min);
copy.add(0, min);
return copy;
}
public List<Integer>
filterRange(List<Integer> list, int min, int max) {
List<Integer> copy = new
ArrayList<Integer>(list);
Iterator<Integer> itr =
copy.iterator();
while(itr.hasNext()) {
int value =
itr.next();
if(value == min
|| value == max || (value > min && value <
max))
itr.remove();
}
return copy;
}
public List<Integer>
intersect(List<Integer> list1, List<Integer> list2)
{
List<Integer> copy1 = new
ArrayList<Integer>(list1);
List<Integer> copy2 = new
ArrayList<Integer>(list2);
List<Integer> intersection =
new ArrayList<Integer>();
Collections.sort(copy1);
Collections.sort(copy2);
Iterator<Integer> itr1,
itr2;
if(copy1.size() > copy2.size())
{
itr1 =
copy1.iterator();
itr2 =
copy2.iterator();
} else {
itr1 =
copy2.iterator();
itr2 =
copy1.iterator();
}
int i = itr1.next();
int j = itr2.next();
while(itr1.hasNext()) {
if(i == j)
{
if(!intersection.contains(i)) {
intersection.add(i);
i = itr1.next();
j = itr2.next();
}
}
else if(i <
j)
i = itr1.next();
else
j = itr2.next();
}
intersection.add(i);
return intersection;
}
public static void main(String[] args) {
ListUtil listUtil = new
ListUtil();
List<Integer> list =
Arrays.asList(new Integer[] {4, 7, 8, 9, 1});
List<Integer> list1 =
Arrays.asList(new Integer[] {4,7,1,3,5});
System.out.println("After minimum
to Front:" + listUtil.minToFront(list));
System.out.println("After filtered
via range:" + listUtil.filterRange(list, 5, 7));
System.out.println("After
intersection:" + listUtil.intersect(list, list1));
}
}
Need some help with this java problem, thanks! Failure to submit will result in a ZERO...
In java please: Write a method that accepts as a parameter a queue of integers that are already sorted by absolute value, and modifies it so that the integers are sorted normally. Only use a single stack as auxiliary storage. For example, if a queue variable named q stores the following elements: front {1, -2, 4, 5, -7, -9, -12, 28, -34} back Then the call of reorder(q); should modify it to store the following values: front {-34, -12, -9,...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
program is C#
Create a program to help some local coffee shops manage their menus Requirements The class contains: 1) A method called defaultMenu that returns a String list and has no parameters. When called, the method returns a string list containing the following elements: {"Coffee", "Americano", Cappuccino" A method called custom Menu that returns a String list and has an int parameter. When called, the method will create a new string list, then ask the user for items to...
Write a method called stutter that accepts an ArrayList of strings and an integer k as parameters and that replaces every string with k copies of that string. For example, if the list stores the values ["how", "are", "you?"] before the method is called and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you?", "you?", "you?", "you?"] after the method finishes executing. If k is 0 or negative, the list should be...
Write a method called alternate that accepts two Lists as its parameters and returns a new List containing alternating elements from the two lists, in the following order: • First element from first list • First element from second list • Second element from first list • Second element from second list • Third element from first list • Third element from second list If the lists do not contain the same number of elements, the remaining elements from the...
write a completed JAVA program (Main included) and make it not interactive but straight to the output Write a method called partition that accepts a list of integers and an integer value E as its parameter, and rearranges (partitions) the list so that all the elements with values less than E occur before all elements with values greater than E The exact order of the elements is unimportant, so long as all elements less than E appear before all elements...
In Java, create a program implementing the functionalities of a standard queue in a class called Queue3503. You will test the functionalities of the Queue3503 class from the main() method of the Main class. In a queue, first inserted items are removed first and the last items are removed at the end (imagine a line to buy tickets at a ticket counter). Do NOT change your class name from "Main". The Main class should come first in your code. Your filename should be "Main.java". The Queue3503 class will contain:...
1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...
Valentine’s Day Question(JAVA) Suppose you had a list with 30 valentines and you stored their names in an array (you hopeless romantic). Then if you had 5 people ask to be your valentine, you would need to make a new array of size 35 (30 + 5) and copy over the original valentines before being able to add the new valentines to the array. This question uses the same logic. Write a program that has a method called doubleSize. The...
1. Write a static method named mode that takes an array of integers as a parameter and that returns the value that occurs most frequently in the array. Assume that the integers in the array appear in sorted order. For example, if a variable called list stores the following values: ist -3, 1, 4, 4, 4, 6, 7,8, 8, 8, 8, 9, 11, 11, 11, 12, 14, int 141i Then the call of mode (li array, appearing four times. st,...