Question: C#Code Exercise 2.4 Class Ball Declare a class Ball with some private data members. 1. A Ball object has a color (type = string) and

C#Code Exercise 2.4 Class "Ball" Declare a class "Ball" with some privateC#Code Exercise

2.4 Class "Ball" Declare a class "Ball" with some private data members. 1. A Ball object has a color (type = string) and a size or "radius (type = double). 2. There are additional class data members, see below. Write a class constructor to set the values of the data members to user input values. Write getters and setters accessors and mutators) for the data members. 1. The color is read-only: it has only a getter/accessor but not a setter. 2. The radius can be changed: it has both a getter and setter, but do not allow the radius to be set to a negative value. Write a public method "deflate" to set the value of the radius to zero. (This is admittedly unrealistic.) Write a public method "volume" to return the volume of the ball. 1. If the radius is r, the volume V is given by the formula V = $ #r3. 2. Beware of integer division when using the above formula. 3. In C# the value of is given by Math.PI. 4. Write "r*r*r" to compute the value of r3. The ball can be kicked, e.g. by people playing a game. 1. Write a public method kick() with return type void. 2. Also write a public method numKicks () which returns the number of times the ball has been kicked (integer). 3. Think about how to implement kick() and numKicks(). Write a main function to instantiate at least two Ball objects and invoke all of the above class methods. 1. Prompt the user to enter suitable input data from the console. 2. Do not allow the input color to be a blank string. 3. Do not allow the input radius to have a negative value. 4. Print the output to the console. Extra: 1. Add extra data members for the "owner" of the ball and the brand name of the ball. 2. These are read-only data members whose values are set in the constructor. 3. Write suitable methods to read the values of the data members

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!