static void Main(string[] args) { Console.Write("Input the desired Shape to get the area: "); string name = Console.ReadLine(); if (name == "Rectangle") { name = "Rectangle"; Console.Write("Enter length of the Rectangle: "); double length = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter breadth of the Rectangle: "); double breadth = Convert.ToDouble(Console.ReadLine()); Rectangle rectangle = new Rectangle(length, breadth, name); Console.WriteLine($"The rectangle araea of length: {length} and breadth: {breadth} is {rectangle.Area()}"); } else if (name == "Triangle") { name = "Triangle"; Console.Write("Enter base of the triangle: "); double tbase = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter height of the triangle: "); double height = Convert.ToDouble(Console.ReadLine()); Triangle triangle = new Triangle(tbase, height, name); Console.WriteLine($"The triangle araea of length: {tbase} and height: {height} is {triangle.Area()}"); } else if (name == "Square") { name = "Square"; Console.Write("Enter length of the square: "); double length = Convert.ToDouble(Console.ReadLine()); Square square = new Square(length, name, 0.0); Console.WriteLine($"The rectangle araea of length: {length} is {square.Area()}"); } else if (name == "Cube") { name = "Cube"; Console.Write("Enter length of the cube side: "); double length = Convert.ToDouble(Console.ReadLine()); Cube cube = new Cube(length, name, 0.0); Console.WriteLine($"The cube araea of length: {length} is {cube.Area()}"); } else { Console.WriteLine("Shape not found, Try typing the first letter of the shape in Uppercase"); } }
static void Main(string[] args) { double num1 = 0; double num2 = 0; Triangle runThis = new Triangle(num1, num2); runThis.Area(); Cube runThis1 = new Cube(num1, num2); runThis1.Area(); Square runThis2 = new Square(num1, num2); runThis2.Area(); Rectangle runThis3 = new Rectangle(num1, num2); runThis3.Area(); }
static void Main(string[] args) { Console.Write("Enter name of Figure: "); string naming = Console.ReadLine(); string name = naming.ToUpper(); if (name == "SQUARE") { Console.Write("Enter the value for X: "); double x = double.Parse(Console.ReadLine()); Square square = new Square(x, x, "square"); Console.Write($"\nThe area of the rectangle is {square.Area()}"); } else if (name == "CUBE") { Console.Write("Enter the value for X: "); double x = double.Parse(Console.ReadLine()); Cube cube = new Cube(x, x, "cube"); Console.Write($"\nThe area of the cube is {cube.Area()}"); } else if (name == "TRIANGLE") { Console.Write("Enter the value for X: "); double x = double.Parse(Console.ReadLine()); Console.Write("Enter the value for Y: "); double y = double.Parse(Console.ReadLine()); Triangle triangle = new Triangle(x, y, "triangle"); Console.Write($"\nThe area of the triangle is {triangle.Area()}"); } else if (name == "RECTANGLE") { Console.Write("Enter the value for X: "); double x = double.Parse(Console.ReadLine()); Console.Write("Enter the value for Y: "); double y = double.Parse(Console.ReadLine()); Rectangle rectangle = new Rectangle(x, y, "rectangle"); Console.Write($"\nThe area of the rectangle is {rectangle.Area()}"); } }
static void GetFigure() { int choice; while (true) { Console.WriteLine("Enter the number corresponding to the shape you want to work with\n1 for Rectangle\n2 for Triangle\n3 for Square\n4 for Cube "); choice = Convert.ToInt32(Console.ReadLine()); if (choice > 0 || choice < 5) { break; } } double len; double width; switch (choice) { case 1: while (true) { Console.WriteLine("Enter length of the rectangle: "); len = Convert.ToInt32(Console.ReadLine()); if (len > 0) { break; } } while (true) { Console.WriteLine("Enter width of the rectangle: "); width = Convert.ToInt32(Console.ReadLine()); if (width > 0) { break; } } Rectangle rect = new Rectangle(len, width); Console.WriteLine($"Area is {rect.Area()}"); break; case 2: while (true) { Console.WriteLine("Enter base of the triangle: "); len = Convert.ToInt32(Console.ReadLine()); if (len > 0) { break; } } while (true) { Console.WriteLine("Enter height of the triangle: "); width = Convert.ToInt32(Console.ReadLine()); if (width > 0) { break; } } Triangle triangle = new Triangle(len, width); Console.WriteLine($"Area is {triangle.Area()}"); break; case 3: while (true) { Console.WriteLine("Enter length of the square: "); len = Convert.ToInt32(Console.ReadLine()); if (len > 0) { break; } } Square square = new Square(len); Console.WriteLine($"Area is {square.Area()}"); break; case 4: while (true) { Console.WriteLine("Enter length of the cube: "); len = Convert.ToInt32(Console.ReadLine()); if (len > 0) { break; } } Cube cube = new Cube(len); Console.WriteLine($"Area is {cube.Area()}"); break; default: break; } }