.NET 4.x Добавить методы, вычисляющие площадь круга и длину окружности - C#
Формулировка задачи:
Добрый день! Помогите пожалуйста добрые люди!
Есть программа работающая с окружностью:
Нужно добавить методы, вычисляющие: площадь круга и длину окружности:
В итоге ничего не работает!!!
using static System.Console;
namespace array
{
class Program
{
// точка входа в программу
static void Main(string[] args)
{
Circle oneCircle = new Circle();
oneCircle.Show();
oneCircle.Set(1, 1, 100);
oneCircle.Show();
// выход из программы
WriteLine("Нажмите любую клавишу для выхода...");
ReadKey(true);
}
}
class Circle
{
public int x = 0;
public int y = 0;
public int radius = 3;
public const double pi = System.Math.PI;
public static readonly string name = "Окружность";
public void Set(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
public void Show()
{
WriteLine("{0} с центром в точке ({1},{2}) радиусом: {3}", name, x, y, radius);
}
}
}using static System.Console;
namespace array
{
class Program
{
// точка входа в программу
static void Main(string[] args)
{
Circle oneCircle = new Circle();
oneCircle.Show();
oneCircle.Set(1, 1, 100);
oneCircle.Set(100);
oneCircle.Show();
// выход из программы
WriteLine("Нажмите любую клавишу для выхода...");
ReadKey(true);
}
}
class Circle
{
public int x = 0;
public int y = 0;
public int radius = 3;
public const double pi = System.Math.PI;
public static readonly string name = "Окружность";
double s; // Площадь круга
double p; // Длина окружности
public void Set(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
public void Set(int radius)
{
this.radius = radius;
}
// Метод для определения площади круга
public void CircumferentialPerimeter(int radius, double p)
{
this.radius = radius;
this.p = p;
p = 2 * System.Math.PI * radius;
}
// Метод для определения длины окружности
public void AreaOfACircle(int radius, double s)
{
this.radius = radius;
this.s = s;
s = System.Math.PI * System.Math.Pow(radius, 2);
}
public void Show()
{
WriteLine("{0} с центром в точке ({1},{2}) радиусом {3}", name, x, y, radius);
WriteLine("Площадь окружности с центром в точке ({0},{1}) радиусом {2} будет: {3}", x, y, radius, s);
WriteLine("Длина окружности с центром в точке ({0},{1}) радиусом {2} будет: {3}", x, y, radius, p);
}
}
}Решение задачи: «.NET 4.x Добавить методы, вычисляющие площадь круга и длину окружности»
textual
Листинг программы
class Program
{
// точка входа в программу
static void Main(string[] args)
{
Circle oneCircle = new Circle();
oneCircle.Show();
oneCircle.Set(1, 1, 100);
oneCircle.Set(100);
oneCircle.Show();
// выход из программы
Console.WriteLine("Нажмите любую клавишу для выхода...");
Console.ReadKey(true);
}
}
class Circle
{
public int x = 0;
public int y = 0;
public int radius = 3;
public static readonly string name = "Окружность";
/// <summary>
/// Площать окружности
/// </summary>
public double Area => GeometryHelper.CircleArea(radius);
/// <summary>
/// Длина окружности
/// </summary>
public double Perimeter => GeometryHelper.CirclePerimeter(radius);
public void Set(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
public void Set(int radius)
{
this.radius = radius;
}
public void Show()
{
Console.WriteLine("{0} с центром в точке ({1},{2}) радиусом {3}", name, x, y, radius);
Console.WriteLine("Площадь окружности с центром в точке ({0},{1}) радиусом {2} будет: {3}", x, y, radius, Area);
Console.WriteLine("Длина окружности с центром в точке ({0},{1}) радиусом {2} будет: {3}", x, y, radius, Perimeter);
}
}
public static class GeometryHelper
{
public static double CircleArea(double radius)
{
return Math.PI * Math.Pow(radius, 2);
}
public static double CirclePerimeter(double radius)
{
return 2 * Math.PI * radius;
}
}