Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is java problem I am not sure what to do please guide me this is the code: import java.util.Random; import java.util.ArrayList; import java.util.Collections; public

This is java problem I am not sure what to do please guide me

this is the code:

import java.util.Random;

import java.util.ArrayList;

import java.util.Collections;

public class Sorting {

public static void main(String[] args) {

int listSize = 30;

int magnitude = 500;

Random rand = new Random(12345);

ArrayList numbers = new ArrayList(listSize);

// Fill the list with random numbers

for (int i=0; i

numbers.add(rand.nextInt() % magnitude);

// Sort and print list

Collections.sort(numbers);

for (Integer num : numbers)

System.out.print(num + " ");

System.out.println();

// Uncomment to test out the backwards ordering class

// Collections.sort(numbers, new BackwardOrdering());

// for (Integer num : numbers)

// System.out.print(num + " ");

// System.out.println();

// Uncomment to test out the alernate ordering class

// Collections.sort(numbers, new AlternateOrdering());

// for (Integer num : numbers)

// System.out.print(num + " ");

}

}

this is the instuction

image text in transcribed

Step 1: Open the file called sorting.java Look through the documentation for the class Gaiiectiona. Specifically, find the method sort, and notice that there is another version of it that takes a comparator object. Step 2: Create a new file called Backwardordering that implements the Comparator interface such that integers are ordered in reverse from their usual ordering. Thern the code for to test your class. Step 3: Create a new file called Alternatingordering that implements the Comparator interface such that positive numbers are ordered as usual, but negative numbers are ordered in reverse. All positive numbers (and zero) are larger than all negative numbers. Add more code to the main method to sort the numbers by this wacky method using Collections.sort (numbers, new Alternatingordering)), then uncomment the code for to test your class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago