Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. Follow the directions in comments.

import java.util.Scanner;

public class Lab7Num1

{public static class Circle implements comparable { //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

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_2

Step: 3

blur-text-image_3

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago