static void Main() { Rectangle rectangle = new Rectangle(3, 5); Console.WriteLine("长方形的面积是:" + rectangle.Area()); Square square = new Square(8); Console.WriteLine("正方形的面积是:" + square.Area()); Triangle triangle = new Triangle(7, 8, 9); Console.WriteLine("三角形的面积是:" + triangle.Area()); }
public static void Main(String[] args) { int hight = Convert.ToInt32(Console.ReadLine()); int width = Convert.ToInt32(Console.ReadLine()); Shape rectangle = new Rectangle(hight, width); Shape triangle = new Triangle(hight, width); rectangle.Area(); triangle.Area(); Console.ReadLine(); }
public void TestTriangle(double a, double b, double c, double area, Type exceptionType) { try { Triangle triangle = new Triangle(a, b, c); double result = triangle.Area(); Assert.True(exceptionType == null, $"Area method is expected to throw {exceptionType}"); Assert.Equal(area, Math.Round(result, 2)); } catch (Exception e) { Assert.Equal(exceptionType, e.GetType()); } }
static void Main(string[] args) { List <Shape> lista; int x; do { Shape.DisplayMenu(); x = int.Parse(Console.ReadLine()); switch (x) { case 1: Console.WriteLine("Generate sample data"); /*{ * Console.Write("Number of random numbers to generate: "); * String line = Console.ReadLine(); * double numbers = 0; * Random rnd = new Random(); * * if (! double.TryParse(line, out numbers)) * numbers = 10; * * for (int i = 1; i <= numbers; i++) * Console.WriteLine("{0}", rnd.Next(0,20)); * Console.ReadLine(); * }*/ break; case 2: Console.WriteLine("Default sort"); break; case 3: Console.WriteLine("Sort by Perimeter"); break; case 4: Console.WriteLine("Filter by Shape type"); break; case 5: Console.WriteLine("Display shapes"); break; } } while (x != 0); Square pole = new Square(10); pole.Area(); pole.Perimeter(); Console.WriteLine("Pole kwadratu: " + pole.Pole); Console.WriteLine("Obwód trójkąta: " + pole.Obwod); Rectangle pole2 = new Rectangle(10, 20); pole2.Area(); pole2.Perimeter(); Console.WriteLine("Pole prostokąta: " + pole2.Pole); Console.WriteLine("Obwód trójkąta: " + pole2.Obwod); Circle pole3 = new Circle(10); pole3.Area(); pole3.Perimeter(); Console.WriteLine("Pole koła: " + pole3.Pole); Console.WriteLine("Obwód trójkąta: " + pole3.Obwod); Triangle pole4 = new Triangle(10, 20, 30); pole4.Area(); pole4.Perimeter(); Console.WriteLine("Pole trójkąta: " + pole4.Pole); Console.WriteLine("Obwód trójkąta: " + pole4.Obwod); }