Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a

Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a set method for the radius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius. It should also contain the definition of an exception class named IllegalRadius, which will contain a double data member called badRadius and a constructor that takes a double and uses it to initialize badRadius (see example on pages 995-6). The static maxRadius data member should be initialized to 10.0 (see example on page 710). The Circle constructor that takes a parameter should throw an IllegalRadiusException if the parameter exceeds the maxRadius.

Write a main function in a separate file. It should ask the user to input a value for the maximum radius and sets maxRadius to that value. It should then ask the user for a radius, and then create a Circle with that radius. Next it should print out the area of that Circle. Your function should use try/catch to handle the possible exception. If an IllegalRadius exception is thrown, the program should print out an error message as shown below.

Enter the maxRadius for Circles. 7.0 Enter the radius for a new Circle object. 6.0 The Circle object was successfully created. The area of the circle is 113.097. 
Enter the maxRadius for Circles. 6.0 Enter the radius for a new Circle object. 7.0 The Circle object could not be created. A radius of 7 exceeds the maximum allowed radius. 

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Distinguish between a commodity rate and a class rate.

Answered: 1 week ago

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago