Question: a) Create a Java class named Circle that implements java.io.Serializable interface and models a circle based on radius. Radius cannot be less than zero. Implement

a) Create a Java class named Circle that implements java.io.Serializable interface and models a circle based on radius. Radius cannot be less than zero. Implement the getter and setter method for radius. Also include an overriding of toString in the circle class. Create the class' comparator which compares two objects of type Circle.

b) Implement the following generic Java method using an O(n^2) sort and a comparator: public static void aSort(E[] list, Comparator comparator) Write test program that creates a list of at least 5 elements of the class type created in problem 3 above, calls the above method to sort the list, then outputs the sorted list via calls to toString.

This is what I have so far. I don't know how to do Part B

import java.io.Serializable;

public class Circle implements Serializable {

private int radius = 1;

public Circle() { }

public Circle(int radius) { setRadius(radius);

}

public void setRadius(int v) { if (v > 0) { this.radius = v; }

}

public int getRadius() { return this.radius;

}

@Override public String toString() { return "Circle{" + "radius=" + radius + '}'; } }

import java.util.Comparator;

public class CompareCircle implements Comparator {

@Override public int compare(Circle o1, Circle o2) { int radius1 = o1.getRadius(); int radius2 = o2.getRadius(); if (radius1 < radius2){ return radius2; } if (radius1 == radius2){ return radius1; } else return radius1; } }

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!