Question: Alter the circle class provided here to include a compareTo method. Make any other changes you need to the class, but DO NOT change the

Alter the circle class provided here to include a compareTo method. Make any other changes you need to the class, but DO NOT change the toString method (or your output will be wrong). Add code to the main method as specified.

import java.util.Scanner;

public class Lab7Num1

{public static class Circle { //attribute private double radius; //constructors public Circle() {radius=0.0; } public Circle(double r) {radius=r; } //accessors public double getRadius() { return radius; } //mutators public void setRadius(double r) { radius = r; } //methods public double circumference() { return 2*Math.PI*radius; } public double area() { return Math.PI*radius* radius; } public String toString() { return "Circle of radius " + radius; } public int compareTo(Circle c) { //write your code here } } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); ArrayListmyC = new ArrayList(); Circle c1; //input the number of circles int howMany = keyboard.nextInt(); //loop howMany times, //each time input a double, create a circle, add it to the ArrayList //sort the ArrayList //output the ArrayList } }

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!