C# newbie
Hello and thank you for taking a moment to read this message. I am new to C# and am just working through some exercises in a book I just purchased. The exercise I am having trouble with askes me to do the following:
Create a class named TestCircle whose Main() method declares three class Circle objects. Using a SetRadius() method from the more general Circle class, assign a small radius value to one circle, assign a larger radius to another Circle. Do not assign a value to the radius of a third circle; instead, retain a value assigned at construction. Call ComputeDiameter() and ComputeArea() for each circle and display the results.
Here is my code:
using System;
class Circle
{
public int Radius =1;
private int Diameter;
private double Area;
/*Here are your Set Methods for this class*/
public int SetRadius(int r)
{
Radius= r;
ComputeDiameter();
ComputeArea();
}
/*Here are your Get Methods for this class*/
public int GetRadius()
{
return Radius;
}
public int GetDiameter()
{
return Diameter;
}
public double GetArea()
{
return Area;
}
/*Here are your Compute Methods for this class*/
public int ComputeDiameter()
{
(radius*2)=Diameter;
}
public double ComputeArea()
{
Area =(radius*radius)* 3.14;
}
}
public class TestCircle
{
public static void Main()
{
Circle firstCircle =new Circle();
firstCircle.SetRadius(2);
Console.Writeline("My first circle has a diameter of {0} and a an area of{1}",firstCircle.GetDiameter(), firstCircle.GetArea());
Circle secondCircle= new Circle();
secondCircle=SetRadius(4);
Console.Writeline("My second circle has a diameter of {0} and a an area of{1}",secondCircle.GetDiameter(), thirdCircle.GetArea());
Circle thirdCircle= new Circle();
Console.Writeline("My third circle has a diameter of {0} and a an area of{1}",thirdCircle.GetDiameter(), thirdCircle.GetArea());
}
}
Visual Studio Gives me the following Errors:
'Circle.SetRadius(int)': not all code paths return a value
' The left-hand side of an assignment must be a variable, property or indexer
'Circle.ComputeArea()': not all code paths return a value
Any help would be greatly appreciated. - Jason
|