Write a class called Circle that contains: a. Three private instance variables: radius (of the type double), color (of the type String), and area (of type double). b. Two constructors - a default constructor with no argument (default value of radius is 2.0, and color is Green) and a parameterized constructor, which initializes only the radius and the color variables. c. Getter and setter for the radius and color variables. d. Two public methods: calculateArea(), and getPerimeter, which return the area and perimeter of a circle instance, respectively. Both methods have return. Then write a driver class that tests the Circle class. In the driver class, create two objects of Circle class, one that tests the default constructor of the Circle class (here no user input is required) and then get the color, radius, area, and perimeter of that object and display them. The second object should test the parameterized constructor (here you need to ask user to give you input to initialize the class variables). The code should ensure that the radius given by the user is positive. If the radius is not positive, the code will keep asking the user to reenter a value. Once the radius is positive, the code should get the color, radius, area, and perimeter of that object accordingly and display them. Then you need to ask the user again to give you a new radius for the second object of the class Circle. Again, the code should ensure that the new radius given by the user is positive. If the radius is not positive, the code will keep asking the user to reenter a value. Then you need to read the new radius and calculate the new area and perimeter accordingly and display them. You need to format your output to look as below (print only 4 values after decimal). • To ensure that the radius is positive, loop (with sentinel) and conditional should be used otherwise you will lose marks. • If the class variables are not private, you will lose marks. • If you don’t create setter/getter methods, you will lose marks. • If you don’t do formatting for the output as requested, you will lose marks. • Don’t hardcode the output otherwise marks will be deducted.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a class called Circle that contains:
a. Three private instance variables: radius (of the type double), color (of the
type String), and area (of type double).
b. Two constructors - a default constructor with no argument (default value of radius
is 2.0, and color is Green) and a parameterized constructor, which initializes only
the radius and the color variables.
c. Getter and setter for the radius and color variables.
d. Two public methods: calculateArea(), and getPerimeter, which return the area
and perimeter of a circle instance, respectively. Both methods have return.
Then write a driver class that tests the Circle class. In the driver class, create two objects
of Circle class, one that tests the default constructor of the Circle class (here no user input
is required) and then get the color, radius, area, and perimeter of that object and display
them.


The second object should test the parameterized constructor (here you need to ask user
to give you input to initialize the class variables). The code should ensure that the radius
given by the user is positive. If the radius is not positive, the code will keep asking the user
to reenter a value. Once the radius is positive, the code should get the color, radius, area,
and perimeter of that object accordingly and display them. Then you need to ask the user
again to give you a new radius for the second object of the class Circle. Again, the code
should ensure that the new radius given by the user is positive. If the radius is not positive, the code will keep asking the user to reenter a value. Then you need to read the new
radius and calculate the new area and perimeter accordingly and display them.


You need to format your output to look as below (print only 4 values after decimal).
• To ensure that the radius is positive, loop (with sentinel) and conditional should
be used otherwise you will lose marks.
• If the class variables are not private, you will lose marks.
• If you don’t create setter/getter methods, you will lose marks.
• If you don’t do formatting for the output as requested, you will lose marks.
• Don’t hardcode the output otherwise marks will be deducted.

The output should be as follow:
The first circle is Green and has radius of 2.0, area of 12.5664 and perimeter of 12.5664
Please enter the radius for the second circle:
-2
Please enter a positive value of the radius for the second circle:
6
Please enter color for the second circle:
Yellow
The second circle is Yellow and has radius of 6.0, area of 113.0973 and perimeter of 37.6991
Please enter the new radius for the second circle:
-9.6
Please enter a positive value of the new radius for the second circle:
8.5
The radius of the Yellow became 8.5, its area now is 226.9801 and its perimeter is now 53.4071
Transcribed Image Text:The output should be as follow: The first circle is Green and has radius of 2.0, area of 12.5664 and perimeter of 12.5664 Please enter the radius for the second circle: -2 Please enter a positive value of the radius for the second circle: 6 Please enter color for the second circle: Yellow The second circle is Yellow and has radius of 6.0, area of 113.0973 and perimeter of 37.6991 Please enter the new radius for the second circle: -9.6 Please enter a positive value of the new radius for the second circle: 8.5 The radius of the Yellow became 8.5, its area now is 226.9801 and its perimeter is now 53.4071
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education