C Sharp How do I format my code to 2 decimal places whem I am calling my code in Main using System.Threading.Tasks; namespace ssullivan_A2_1.cs{ class Program { //The output should display the Object Type (Circle, Square or Triangle) //the values used to initialize the shape, the area, and the perimeter static void Main(string[] args) { ////Store the objects in a Collection object (List, Array, HashSet, etc...) objects in the collection will be of type Shape Shapes[] arrayOfShapes = new Shapes[3]; arrayOfShapes[0] = new Circle(5);// arrayOfShapes[1] = new Rectangle(5, 5);// arrayOfShapes[2] = new Triangle(3, 5, 5);// //the values used to initialize the shape, the area, and the perimeter foreach (Shapes objects in arrayOfShapes) {// use arrayOfShapes to call methods //The output should display the Object Type (Circle, Square or Triangle) //the values used to initialize the shape, the area, and the perimeter // use objects to call functions ( //GetType().Name} returns the name of the object // use $ and { } when calling the object with the fubction Console.WriteLine($"The area of {objects.GetType().Name} is: {objects.CalculateArea() }"); Console.WriteLine($"The perimeter of {objects.GetType().Name} is: {objects.CalculatePerimeter()}"); } } The area of Circle is: 19.6349540849362 // I want this to be 2 decimal places The perimeter of Circle is: 15.707963267949 //I want this to be 2 decimal places The area of Rectangle is: 25The perimeter of Rectangle is: 20The area of Triangle is: 0The perimeter of Triangle is: 11Press any key to continue . . .
C Sharp How do I format my code to 2 decimal places whem I am calling my code in Main
using System.Threading.Tasks;
namespace ssullivan_A2_1.cs
{
class Program
{
//The output should display the Object Type (Circle, Square or Triangle)
//the values used to initialize the shape, the area, and the perimeter
static void Main(string[] args)
{ ////Store the objects in a Collection object (List, Array, HashSet, etc...) objects in the collection will be of type Shape
Shapes[] arrayOfShapes = new Shapes[3];
arrayOfShapes[0] = new Circle(5);//
arrayOfShapes[1] = new Rectangle(5, 5);//
arrayOfShapes[2] = new Triangle(3, 5, 5);//
//the values used to initialize the shape, the area, and the perimeter
foreach (Shapes objects in arrayOfShapes)
{// use arrayOfShapes to call methods
//The output should display the Object Type (Circle, Square or Triangle)
//the values used to initialize the shape, the area, and the perimeter
// use objects to call functions (
//GetType().Name} returns the name of the object
// use $ and { } when calling the object with the fubction
Console.WriteLine($"The area of {objects.GetType().Name} is: {objects.CalculateArea() }");
Console.WriteLine($"The perimeter of {objects.GetType().Name} is: {objects.CalculatePerimeter()}");
}
}
The area of Circle is: 19.6349540849362 // I want this to be 2 decimal places
The perimeter of Circle is: 15.707963267949 //I want this to be 2 decimal places
The area of Rectangle is: 25
The perimeter of Rectangle is: 20
The area of Triangle is: 0
The perimeter of Triangle is: 11
Press any key to continue . . .
Trending now
This is a popular solution!
Step by step
Solved in 2 steps