Hi I have this project I'm working on and I'm totally stuck.
Things is that we need to do the following:
A - Write a class, Sphere, which has one private field of the type integer which represent the radius of the sphere.
B - Write a default, empty, constructor and a constructor that takes one parameter, the sphere’s radius.
C - Write a property that allows the class user to modify the radius.
D - Write methods that calculate the volume of the sphere.
Well i have started and I think I got it right until part D, I dont know how to use the method i get from the user in a metod. How to pass it's value into the metod, run the calculation and then return it to the user.
Here's my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Sphere
{
public int sphereradius
{
get
{
return userradius;
}
set
{
userradius = value;
}
}
public Sphere()
{
//Empty constructor
}
public Sphere(int sphereradius, int userradius)
{
//Constructor that takes the sphere radius parameter
sphereradius = int.Parse(Console.ReadLine());
}
public override string ToString()
{
return "" + sphereradius;
}
static void Main(string[] args)
{
//Creates object
Sphere sphereradius = new Sphere();
//Takes user value
Console.Write("Enter radius: ");
sphereradius.userradius = int.Parse(Console.ReadLine());
// Checks userinput
Console.WriteLine("Sphereradius details; {0}", sphereradius);
//Calculate volume of sphere
}
static void calculatevolume(int sphereradius)
{
//This is were i cant get the value from the user input to be calculated...?!?
//as you can see Iv'e tried to send it into the method.
}
}
}