In Java. Define the class InvalidSideException, which inherits from the Exception class. Also define a Square class, which has one method variable -- an int describing the side length. The constructor of the Square class should take one argument, an int meant to initialize the side length; however, if the argument is not greater than 0, the constructor should throw an InvalidSideError. The Square class should also have a method getArea(), which returns the area of the square. Create a Driver class with a main method to test your classes. Your program should prompt the user to enter a value for the side length, and then create a Square object with that side length. If the side length is valid, the program should print the area of the square. Otherwise, it should catch the InvalidExceptionError, print "Side length must be greater than 0.", and terminate the program. The words for output is highlighted in grey and yellow in the blue box. Class should be named Driver, as shown in blue box as well.
In Java.
Define the class InvalidSideException, which inherits from the Exception class. Also define a Square class, which has one method variable -- an int describing the side length. The constructor of the Square class should take one argument, an int meant to initialize the side length; however, if the argument is not greater than 0, the constructor should throw an InvalidSideError. The Square class should also have a method getArea(), which returns the area of the square.
Create a Driver class with a main method to test your classes. Your
The words for output is highlighted in grey and yellow in the blue box. Class should be named Driver, as shown in blue box as well.
![Define the class InvalidSideException, which inherits from the Exception class. Also define a Square class, which has one method variable -- an int
describing the side length. The constructor of the Square class should take one argument, an int meant to initialize the side length; however, if the
argument is not greater than 0, the constructor should throw an InvalidSideError. The Square class should also have a method getArea(), which
returns the area of the square.
Create a Driver class with a main method to test your classes. Your program should prompt the user to enter a value for the side length, and then
create a Square object with that side length. If the side length is valid, the program should print the area of the square. Otherwise, it should catch
the InvalidExceptionError, print "Side length must be greater than 0.", and terminate the program.
SAMPLE RUN #1: java Driver
Interactive Session
Hide Invisibles
Enter side length of square: -13<
Side length must be greater than 0.<
Highlight: Full Standard Output
Show Highlighted Only](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F646169b5-7e20-4fe5-b32d-838c752dcc8e%2F6efe49b5-d043-49ee-b17d-48ff3ad4da47%2Frq07eqp_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Could you please add some comments in the code?
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)