Code Language: C# (much appreciated!) Scenario : -Write a console program that u
ID: 3801521 • Letter: C
Question
Code Language: C# (much appreciated!)
Scenario:
-Write a console program that uses a Circle class to calculate a circle's area, diameter, and circumference given the circle's radius.
Fields (property):
- The circle's radius: a double, read and write
Constant:
- PI: constant value of 3.14159
Methods:
- Constructor: Accepts the radius of the circle as an argument
- Constructor: A no argument constructor that sets the radius to 0
- GetArea: Returns the area of the circle, which is calculated as: Area = PI*radius*radius
- GetDiameter: Returns the diameter of the circle, which is calculated as: Diameter = radius*2
- GetCircumference: Returns the circumference of the circle, which is calculated as: Circumference = 2*PI*radius
Processing:
Write a program that demonstrates the circle class by asking the user for the circle's radius, creating a circle object, and then reporting the circle's area, diameter and circumference.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Text;
public class Circle
{
static void Main(string[] args)
{
double radious;
double Area;
double pi = 3.14;
Console.WriteLine("enter the radius.");
Console.ReadLine();
radious = Convert.ToDouble(Console.ReadLine());
Area = (pi * r * r);
Console.WriteLine("The area of the circle is" + Area);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.