Question: Java programming Task 1 Sorting objects You should create a Java application that uses interface Comparable so that it is possible to sort geometric objects

Java programming

Task 1

Sorting objects

You should create a Java application that uses interface Comparable so that it is possible to sort geometric objects of type cool. We're going to sort bullets by volume as criteria. That is, the bullets with the greatest volume should be printed first if they are located in a sorted array.

Create a class called ComparableSphere, which expands (extends) Sphere that comes from the Circle class we've worked with in the past). Feel free to use geometricObjectsDemo.java which is located under files at week6 in Canvas. UML chart on page 2 displays the class hierarchy.

The Class ComparableSphere will also implement interface Comparable (implements)

Comparable). Then a new implementation must be created (override) of the compareTo method from Comparable.

In the main method, you should write code to test the implementation by comparing two or more bullet objects and printing them sorted by volume.

Tips. Use the Arrays.sort static method to sort bullets if they are in an array. See Listing 13.10 on page 538 of the syllabus.

This is about the same task as Programming exercise 13.22 (The Comparable class) in the curriculum book.

UML diagram for Oblig2

Below is the oblig2 class hierarchy. You do not need to implement the methods in the Circle class. However, if you use the Circle class from GeometricObjectsDemoV2.java in week7, the methods in the UML chart will be included.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!