2- Write a class called Circle that contains: a. Three private instance variables: radius (of the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2- 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 2- 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
Expert Answer:
Answer rating: 100% (QA)
Heres the Java implementation of the Circle class and t... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
1. Sketch the unit step response (u(s) = 1/s) for the following transfer functions: (a) G(s) 3 = 4s1 5 (b) G(S) = (c) G(s) (d) G(s) (e) G(s) = = = (s+1)(s2 2s+4) 1 2s2+s+1 2s+1 4s +1 2 s2+2
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
We look at the accumulated area beneath this curve, as in the definite integral as follows F(x) = f(t) dt -2 { F(x) = int_(-2)^x f(t) dt a) Use ordinary area formulas to compute each of the...
-
Write the form of the partial fraction decomposition of the rational expression. Do not solve for the constants. 1. 3 / x2 + 20x 2. x - 8 / x2 - 3x - 28 3. 3x - 4 / x3 - 5x2 4. x - 2 / x(x2 + 2)2
-
For these exercises, perform each of these steps. Assume that all variables are normally or approximately normally distributed. a. State the hypotheses and identify the claim. b. Find the critical...
-
List and describe the factors a creditor may use when asking a court to set aside an alleged fraudulent transfer of property under the Uniform Fraudulent Transfer Act (UFTA).
-
Brenda Lewis had been employed for two years at Heartland Inns of America, LLC, and gradually worked her way up the management ladder. Lewis, who described herself as a tomboy, was commended for her...
-
8. Money and Foreign exchange markets in Frankfurt and NY are very efficient and reflect the following information Spot Ex rate 1-yr TB rate a) $0.9000/Euro London 6.5% Unknown NY $0.9000/Euro 3.20%...
-
Pizza Corporation acquired 80 percent ownership of Slice Products Company on January 1, 20X1, for $160,000. On that date, the fair value of the noncontrolling interest was $40,000, and Slice reported...
-
What concepts, theories, and/or stories counted as knowledge when you were a K-12 student? What tools helped you to gain that knowledge at that time?
-
Solve the following rational equations. State any extraneous solutions. (3) (x-2) = (3x) (x(2) -4x+3)
-
(1) Describe why in the absence of external magnetic field, a bulk object exhibit no net nuclear magnetism. (2) What are the primary functions of the static magnetic field in MR imaging? (3) What is...
-
Double-glazed windows are usually made of two glass panes with a thin layer of air sealed between the panes. a. Why do these windows reduce heat loss to a much greater extent than occurs if the...
-
The School" is not meant to be realistic. Why do you think the author might write the story this way? Use specific examples from the brief story to support your opinion How does Barthelme use humor...
-
Tiny Tots Transit has 3 operating divisions Cam, Nate and Ash. Corporate headquarters in Tuscaloosa incurs $3,500,000 per period which the company considers as an indirect cost of the operating...
-
Write a paper detailing a geographic information system (GIS) of your own design that would utilize data in an original manner.
-
Write the following method that returns the location of the largest element in a two-dimensional array. public static int[] locateLargest(double[][] a) The return value is a one-dimensional array...
-
Write a program that creates a Date object, sets its elapsed time to 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, and 100000000000, and displays the date and time using the...
-
Assume a runner runs 24 miles in 1 hour, 40 minutes, and 35 seconds. Write a program that displays the average speed in kilometers per hour.
-
Many of the living organisms in Hawaii are found nowhere else on Earth. Hawaii has numerous unique species of plants, birds, insects, mammals, mushrooms, and other living things. Why?
-
Islands tend to have fewer species than the mainlands they resemble. Furthermore, island species often include many flying organisms and few terrestrial ones. Do these biogeographic patterns support...
-
Laura says she doesnt believe that humans were at one time chimpanzees or gorillas. Jeff says he doesnt believe it either. Explain why biologists also dont believe that humans are descended from...
ECG Interpretation For The Clinical Exercise Physiologist 2nd Edition - ISBN: 1975182367 - Free Book
Study smarter with the SolutionInn App