JAVA Program ASAP
Here is a Sort.java program. Create A FileSorting.java program so it runs and passes the test cases in Hypergrade.
import java.util.ArrayList;
public class Sort {
public static <E extends Comparable<? super E>> void insertionSort(E[] array) {
for (int i = 1; i < array.length; i++) {
for (int j = i; j > 0 && array[j].compareTo(array[j - 1]) < 0; j--) {
swap(array, j, j - 1);
}
}
}
public static <E extends Comparable<? super E>> void insertionSort(ArrayList<E> arrayList) {
for (int i = 1; i < arrayList.size(); i++) {
for (int j = i; j > 0 && arrayList.get(j).compareTo(arrayList.get(j - 1)) < 0; j--) {
swap(arrayList, j, j - 1);
}
}
}
public static <E extends Comparable<? super E>> void bubbleSort(E[] array) {
for (int i = 0; i < array.length - 1; i++) {
for (int j = array.length - 1; j > i; j--) {
if (array[j].compareTo(array[j - 1]) < 0) {
swap(array, j, j - 1);
}
}
}
}
public static <E extends Comparable<? super E>> void bubbleSort(ArrayList<E> arrayList) {
for (int i = 0; i < arrayList.size() - 1; i++) {
for (int j = arrayList.size() - 1; j > i; j--) {
if (arrayList.get(j).compareTo(arrayList.get(j - 1)) < 0) {
swap(arrayList, j, j - 1);
}
}
}
}
public static <E extends Comparable<? super E>> void selectionSort(E[] array) {
for (int i = 0; i < array.length - 1; i++) {
int lowindex = i;
for (int j = array.length - 1; j > i; j--)
if (array[j].compareTo(array[lowindex]) < 0)
lowindex = j;
swap(array, i, lowindex);
}
}
public static <E extends Comparable<? super E>> void selectionSort(ArrayList<E> arrayList) {
for (int i = 0; i < arrayList.size() - 1; i++) {
int lowindex = i;
for (int j = arrayList.size() - 1; j > i; j--)
if (arrayList.get(j).compareTo(arrayList.get(lowindex)) < 0)
lowindex = j;
swap(arrayList, i, lowindex);
}
}
private static <E> void swap(E[] array, int p1, int p2) {
E temp = array[p1];
array[p1] = array[p2];
array[p2] = temp;
}
private static <E> void swap(ArrayList<E> arrayList, int p1, int p2) {
E temp = arrayList.get(p1);
arrayList.set(p1, arrayList.get(p2));
arrayList.set(p2, temp);
}
}
input2x2.csv
-67,-11
-27,-70
input1.csv
10
input10x10.csv
56,-19,-21,-51,45,96,-46
-27,29,-58,85,8,71,34
50,51,40,50,100,-82,-87
-47,-24,-27,-32,-25,46,88
-47,95,-41,-75,85,-16,43
-78,0,94,-77,-69,78,-25
-80,-31,-95,82,-86,-32,-22
68,-52,-4,-68,10,-14,-89
26,33,-59,-51,-48,-34,-52
-47,-24,80,16,80,-66,-42
input0.csv
Test Case 1
input1.csvENTER
10\n
Test Case 2
input2x2.csvENTER
-67,-11\n
-70,-27\n
Test Case 3
input10x10.csvENTER
-51,-46,-21,-19,45,56,96\n
-58,-27,8,29,34,71,85\n
-87,-82,40,50,50,51,100\n
-47,-32,-27,-25,-24,46,88\n
-75,-47,-41,-16,43,85,95\n
-78,-77,-69,-25,0,78,94\n
-95,-86,-80,-32,-31,-22,82\n
-89,-68,-52,-14,-4,10,68\n
-59,-52,-51,-48,-34,26,33\n
-66,-47,-42,-24,16,80,80\n
Test Case 4
input0.csvENTER
File input0.csv is empty.\n
Test Case 5
input2.csvENTER
File input2.csv is not found.\n
Please re-enter the file name or type QUIT to exit:\n
input1.csvENTER
10\n
Test Case 6
quitENTER
Test Case 7
input2.csvENTER
File input2.csv is not found.\n
Please re-enter the file name or type QUIT to exit:\n
QUITENTER
Step by stepSolved in 4 steps with 3 images
- Please answer the problem in the screenshot. Please use the methods below as a base. The language is in Java. import java.util.*; class HeapMax { // we go with arraylist instead of array for size flexibility private ArrayList<Integer> data; // DO NOT MODIFY THIS METHOD public HeapMax() { data = new ArrayList<Integer>(0); } // insert a new element and restore max heap property public void insert(int element) { } // return max public int getMax() { // remove this line return 0; } // remove max and restore max heap property public int removeMax() { // remove this line return 0; } // heap builder public void build(int[] arr) { } // print out heap as instructed in the handout public void display() { } // you are welcome to add any supporting methods }arrow_forwardGiven an array of numbers, and an integer, find the last index that that integer appears in the array. If the number is not found, return -1. import java.util.ArrayList;public class LastIndexFound{public static int solution(ArrayList<Integer> nums, int numToFind){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;}}arrow_forwardTrace insertion sort for list ={18,57,8,89,7}arrow_forward
- Java Foundations Consider the following Java method to reverse an array, i.e. rearrange its elements to the opposite order. An array containing {1, 3, 5} would contain {5, 3, 1} after being reversed. public static void arrayReverse(int[] array) { int le, ri; for (le = 0, ri = array.length - 1; le < array.length / 2; le++, ri--) { int temp = array[le]; array[le] = array[ri]; array[ri] = temp; } } Write the worst-case runtime efficiency of arrayReverse in BigOh notation.arrow_forwardjava Create a method that: is called timesTwo returns an ArrayList of Integers takes in a single parameter - an ArrayList of Integers called nums This method should take the ArrayList parameter and multiply every value by two. public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.nextInt()); } System.out.println(timesTwo(list)); } }arrow_forwardJAVA The following code for InsertionSort is given to us by the textbook. Trace the code stepby step using the array[55, 22, 77, 99, 66, 33, 11]on a piece of paper or using a Word document. If the code has errors, correct it and make itwork.public static void insertionSort(double[] list) {for (int i = 1; i < list.length; i++) {/** insert list[i] into a sorted sublist list[0..i-1] so thatlist[0..i] is sorted. */double currentElement = list[i];int k;for (k = i - 1; k >= 0 && list[k] > currentElement; k--) {list[k + 1] = list[k];}// Insert the current element into list[k+1]list[k + 1] = currentElement;}}arrow_forward
- Please use the template provided below and make sure the output matches exactly. import java.util.Scanner;import java.util.ArrayList; public class PhotoLineups { // TODO: Write method to create and output all permutations of the list of names. public static void printAllPermutations(ArrayList<String> permList, ArrayList<String> nameList) { } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> permList = new ArrayList<String>(); String name; // TODO: Read in a list of names; stop when -1 is read. Then call recursive method. }}arrow_forwardThis codes not complie it can you fix the code can complie it? import java.util.ArrayList; public class Heap { void heapify(ArrayList hT, int i) { int size = hT.size(); int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < size && hT.get(l) > hT.get(largest)) largest = l; if (r < size && hT.get(r) > hT.get(largest)) largest = r; if (largest != i) { int temp = hT.get(largest); hT.set(largest, hT.get(i)); hT.set(i, temp); heapify(hT, largest); } } void insert(ArrayList hT, int newNum) { int size = hT.size(); if (size == 0) { hT.add(newNum); } else { hT.add(newNum); for (int i = size / 2 - 1; i >= 0; i--) { heapify(hT, i); } } } void deleteNode(ArrayList hT, int num) { int size = hT.size(); int i; for (i = 0; i < size; i++) { if (num == hT.get(i)) break; } int temp = hT.get(i); hT.set(i,…arrow_forwardWrite a java class named First_Last_Recursive_Merge_Sort that implements the recursive algorithm for Merge Sort. You can use the structure below for your implementation. public class First_Last_Recursive_Merge_Sort { //This can be used to test your implementation. public static void main(String[] args) { final String[] items = {"Zeke", "Bob", "Ali", "John", "Jody", "Jamie", "Bill", "Rob", "Zeke", "Clayton"}; display(items, items.length - 1); mergeSort(items, 0, items.length - 1); display(items, items.length - 1); } private static <T extends Comparable<? super T>> void mergeSort(T[] a, int first, int last) { //<Your implementation of the recursive algorithm for Merge Sort should go here> } // end mergeSort private static <T extends Comparable<? super T>> void merge(T[] a, T[] tempArray, int first, int mid, int last) { //<Your implementation of the merge algorithm should go here> } // end merge //Just a quick method to display the whole array. public…arrow_forward
- Correct my codes in java // Arraysimport java.util.Scanner;public class Assignment1 {public static void main (String args[]){Scanner sc=new Scanner (System.in);System.out.println("Enter mark of student");int n=sc.nextInt();int a[]=new int [n];int i;for(i=0;i<n;i++){System.out.println("Total marks of student in smster");a[i]=sc.nextInt();}int sum=0;for(i=0;i<n;i++){sum=sum+a[i];}System.out.println("Total marks is :");for (i=0;i<n;i++);{System.out.println(a[i]);}System.out.println();}}arrow_forwardJAVA PROGRAM MODIFY THIS PROGRAM SO IT READS THE TEXT FILES IN HYPERGRADE. I HAVE PROVIDED THE INPUTS AND THE FAILED TEST CASE AS A SCREENSHOT. HERE IS THE WORKING CODE TO MODIFY: import java.io.*;import java.util.*;public class NameSearcher { private static List<String> loadFileToList(String filename) throws FileNotFoundException { List<String> namesList = new ArrayList<>(); File file = new File(filename); if (!file.exists()) { throw new FileNotFoundException(filename); } try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String[] names = line.split("\\s+"); for (String name : names) { namesList.add(name.toLowerCase()); } } } return namesList; } private static Integer searchNameInList(String name, List<String> namesList) {…arrow_forwardCode debug JAVA import java.util.ArrayList;public class ArrayList {public static ArrayList<Integer> reverse(ArrayList<Integer> list) {for (int i = 0; i < list.size(); i++) {System.out.println(list);}public static ArrayList<Integer> getReverse(ArrayList<Integer> list){for (int index = 0; index < list.size() / 2; index++) {int temp = list.get(index);list.set(index, list.get(list.size() - index - 1));//swaplist.set(list.size() - index - 1, temp); //swap}return list;}}public static void main(String[] args) {ArrayList<Integer> list = new ArrayList<>();list.add(1);list.add(2);list.add(3);System.out.println("Original elements : " + list);System.out.println("Reversed elements : " + getReverse(list));}}arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education