Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started