Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment: In this assignment, you will be implementing versions of two sorting algorithms. You will use them to sort an array of objects representing cubes.

Assignment: In this assignment, you will be implementing versions of two sorting algorithms. You will use them to sort an array of objects representing cubes. Your first step is to implement a class called Cube that has three double variables to store the length, width, and height of the cube. Then, write a method that calculates the volume of the Cube as a member of the class. All other requirements are listed below.

Next, you should write a method in a class named Runner1 that will generate a random list of Cubes for testing. The method should take in a number representing the size of the list, and return an array of that many Cubes. Each Cube should have a randomly generated length, width, and height between 0 and 100.

Implement another method in Runner1 to print out your array of cubes. You should print a line for each cube listing the length, width, and height and then the volume.

As another preliminary step, implement a method CopyArray in Runner1 that creates a new array of cubes with identical values of a given one.

Now, write two methods inside Runner1, one named BubbleSort and the other named SelectionSort. Use parameters as you think appropriate. BubbleSort must implement the bubble sort algorithm we discussed in the class and SelectionSort must implement the selection sort algorithm we discussed in class. Note that both BubbleSort and SelectionSort must sort the cubes in the input array in ascending order of the volumes of the cubes. Demonstrate that your code works by generating a random list of 20 cubes (in an array), printing out the list before you sort it, and then printing out the list again after it is sorted using BubbleSort. For an identical list of 20 cubes (copied right after the generation of the array that was given to BubbleSort as an input), show the list before and after the use of the SelectionSort method.

Write a class named Runner2 that will test the speed of your BubbleSort and SelectionSort methods by recording the time needed to sort an array of different number of cubes (For example, 2000, 3000, 4000, 5000, 6000, and 7000 cubes).

Deliverables: Cube.java, Runner1.java, Runner2.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions