Question

Complicated JAVA writing algorithm questions HELP!static void Q13(ArrayList<Integer input) sort the input ArrayList in increasing order static double Q14 (ArrayList<Integer input) return the median value of the input ArrayList. If the size is even return the average of the two elements closests to the median return 0.0 static int Q15 (ArrayList<Integer input)t return the mode value of the input ArrayList Ties can be broken arbitrarily return 0;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Source code: import java.util.*; public class Arrayclassf static void 213 (ArrayList<Integer> Input) Collections.sortstatic int 915 (ArrayList<Integer> Input) int mode0 int c-0, x, y,temp; for int i- 0 i< Input.size) i+) xInput.get (i); tempreturn mode public static void main (String [largs) ( ArrayList<Integer> list-new ArrayList<Integer; Scanner anew Scanner (SySample Output: 5 2 4 5 2 Array List in sorted order [2, 2, 4, 5, 6] Median of the array list is 4.6e Mode of the array list i

Add a comment
Know the answer?
Add Answer to:
Complicated JAVA writing algorithm questions HELP! Complicated JAVA writing algorithm static void Q13(ArrayList<Integer> input){//sort the input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • static void Q3(ArrayList<Integer> input){//Sort the input ArrayList by absolute value}

    static void Q3(ArrayList<Integer> input){//Sort the input ArrayList by absolute value}

  • //Java (Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList...

    //Java (Sort ArrayList) Write the following method that sorts an ArrayList: public static > void sort(ArrayList list) Write a test program that does the following operations: 4. Creates an empty ArrayList of Integer elements; 5. Generates 20 integer values, drawn at random between 0 and 9 (included), and adds them to the array list; 6. Calls the method sort and prints both the original list, and the sorted one.

  • I want to sort my array by pushing the findMax number to the end of the...

    I want to sort my array by pushing the findMax number to the end of the list with this idea The Idea of sort the arraylist: (assume that the arraylist has n elements)Search the n elements of the arraylist for the maximum value then put this maximum value at the last position of the arraylist. Hence at index n-1. Move all other elements forward. Search the first n- 1 elements of the arraylist for the maximum value then put this...

  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...

  • I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on)...

    I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on) with comments: import java.util.ArrayList; public class Mergesort { /** * Sorts list given using the mergesort algorithm * @param list the list to be sorted * @param first the index of the first element of the list to be sorted * @param last the index of the last element of the list to be sorted */ public static void mergesort(ArrayList<Comparable> list, int first, int...

  • Add another method public static void displayObject(ArrayList list, int n) that will display then information on...

    Add another method public static void displayObject(ArrayList list, int n) that will display then information on the nth object of list. If n is not a valid index, the method should generate and throw and exception that the main can then process. You get to decide what exception (one built into Java or a custom exception) and how you would like to “handle” the exception (terminate the program, prompt for more input, etc). Here is the program so far: import...

  • How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList<Integer>) and...

    How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList<Integer>) and compare with a graph? I have these methods: //This one receives one size(n) parameter    public static ArrayList<Integer> RandomArray(int n){               ArrayList<Integer> randomArray = new ArrayList<Integer>(n);               Random rand = new Random(); //--- random number        rand.setSeed(System.currentTimeMillis());               for(int i = 0; i < n; i++ ) {            //loop for creating...

  • Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating...

    Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then merge returns the array list 1 9 4 7 9 4 16 9 11...

  • Write a program that uses the selection sort algorithm to sort an array of coins by...

    Write a program that uses the selection sort algorithm to sort an array of coins by their value. Name your class SelectionSorter.java and include the method public static void sort(Coin[] a). The following classes are already included: Main.java and Coin.java and do not need to be downloaded and zipped into submission. Console [15, 5, 1, 100, 25, 50] [1, 5, 15, 25, 50, 100] Input Files Coin.java //package Sorting1; /** A coin. */ public class Coin { private int value;...

  • Hi All, Can someone please help me correct the selection sort method in my program. the...

    Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT