Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java From project 2, add exception logic with throwing error within the Circle object and modify your main method to catch that error from the

Java

From project 2, add exception logic with throwing error within the Circle object and modify your main method to catch that error from the Circle object.

Check if Radius is greater than 0. if not, throw an error.

1. in Circle constructor with radius

2. in a setRadius method.

Circle.java

public class Circle extends GeometricObject implements Cloneable, Comparable  { private double radius; public Circle() { } public Circle(double radius) { this.radius = radius; } /** Return radius */ public double getRadius() { return radius; } /** Set a new radius */ public void setRadius(double radius) { this.radius = radius; } @Override /** Return area */ public double getArea() { return radius * radius * Math.PI; } /** Return diameter */ public double getDiameter() { return 2 * radius; } @Override /** Return perimeter */ public double getPerimeter() { return 2 * radius * Math.PI; } /* Print the circle info */ public void printCircle() { System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius); } @Override public String toString() { return super.toString() + " and the radius is " + radius; } @Override public int compareTo(Circle o) { // TODO Auto-generated method stub if (getRadius() >o.getRadius()) return 1; else if (getRadius()  

project2.java

public class Project2 { public static void main(String[] args) { Circle [] circles = { new Circle(3), new Circle(13.24), new Circle (1.5), new Circle(13.22) }; System.out.println("Before Sorting:"); for (Circle circle: circles) { System.out.print(circle + " "); System.out.println(); } java.util.Arrays.sort(circles); System.out.println("After Sorting:"); for (Circle circle: circles) { System.out.print(circle + " "); System.out.println(); } Circle circle = new Circle(4); Circle circle1 = circle; Circle circle2 = (Circle) circle.clone(); System.out.println( "Original circle " +circle); System.out.println("Clone circle " +circle2); } }

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

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

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions