You have C right, the rest are wrong. None of the class methods should have Console anywhere in them.
A) private variable that store radius. You don't have one
B) You have an empty constructor, but where is the one that take ONE parameter (and stores it in the private variable, that's what the private variable is for).
C) You have this right but, usually, properties begin with an upper case character (style issue)
D) You have no method that calculates the volume of the sphere and returns that value (something like public double Volume() {
Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
You can not have two radii. A shpereradius and a userradius are confusing. A sphere just has ONE radius, which has to be a private property of you Sphere class.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
class Sphere
{
/// <summary>
/// A - Write a class, Sphere, which has one private field of the type integer which represent the radius of the sphere.
/// </summary>
private int radius;
/// <summary>
/// B - Write a default, empty, constructor and a constructor that takes one parameter, the sphere’s radius.
/// </summary>
public Sphere()
{
//set default for radius, say maybe one or zero
radius = 1;
}
/// <summary>
/// B - Write a default, empty, constructor and a constructor that takes one parameter, the sphere’s radius.
/// </summary>
/// <param name="radius">a radius you optionally get to initialize your object</param>
public Sphere(int radius)
{
//now that you got it, what do you wanna do with it? test it f its valid?
//or just use it? thats besides the point, what matters is when csc reaches here, you got it
//i'm just gonna do this
this.radius = radius;
}
/// <summary>
/// C - Write a property that allows the class user to modify the radius.
/// </summary>
public int Radius
{
get { return radius; }
set { radius = value; }
}
/// <summary>
/// D - Write methods that calculate the volume of the sphere.
/// Just wrote it wrong, just demonstrating, i don't do math so i dnt even knw a single applicable math
/// you will change it to whateva you have to
/// </summary>
/// <returns>a double valume value for your Sphere</returns>
public double CalcVolume()
{
return radius * Math.PI;
//thus after initializing an object of this type
// you can simply call this method as
//Sphere myS = new Sphere(25);
//Sphere mySS = new Sphere();
//double vol1,vol2;
//vol1 = myS.CalcVolume();
//etc
}
}
This should help, and in future, try read and understand the problem domain then tickle each one by one in an OOP manner. that will better help you solve your coding problems faster and easier.Please marks this post solved if you got what you needed
mshauny
Junior Poster in Training
62 posts since Jan 2010
Reputation Points: 35
Solved Threads: 6
@mshauny: Nice effort:yawn: Now all the OP has to do is copy and paste and in the process of doing so will have learned nothing.
BTW maby the math in your country is quite different than in mine, but here we calculate the volume of a sphere as being :
( 4 / 3 ) * Math.PI * Math.Pow( radius, 3.0)
or
( 4 / 3 ) * Math.PI * radius * radius * radius
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
There are somethings i did wrong in the code. And yes i made a mistake showing him the full code, but he will learn from it atleast, just this once let him learn from other's work. I strongly believe people can benefit alot from open sourced codes, we should'nt be too hash on them just because we learned programing the hardway, besides its now pointless to hide code from a Windows .NET developer using tools like VS because it virtually explains everything to them. I'm sorry though, thats just how i teach my fellow students.
On the Math part, Its not about country to country application. I'm not a math person indeed. Thanks for the Volume formular, i just did a dummy calculation to demonstrate a point not to be precise.
Thanks for your input guys
mshauny
Junior Poster in Training
62 posts since Jan 2010
Reputation Points: 35
Solved Threads: 6
No harm done mshauny. :)
But you should better have replaced your "calculation" with something like:
//calculation of volume done here
Happy computing!
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661