public override Shape CreateShape() { try { Console.WriteLine("Кольцо задается точкой центра (X, Y), внешним радиусом R и внутренним радиусом r"); PointCreator pointCreator = new PointCreator(); Point p = (Point)pointCreator.CreateShape(); double outerRadius = 0; bool isSuccessOuterRadius = false; while (!isSuccessOuterRadius) { Console.WriteLine("Введите R"); isSuccessOuterRadius = double.TryParse(Console.ReadLine(), out outerRadius); } double innerRadius = 0; bool isSuccessInnerRadius = false; while (!isSuccessInnerRadius) { Console.WriteLine("Введите r"); isSuccessInnerRadius = double.TryParse(Console.ReadLine(), out innerRadius); } return(new Ring(p, innerRadius, outerRadius)); } catch (Exception exception) { throw new Exception(exception.Message + Environment.NewLine + "Кольцо не создано"); } }
public override Shape CreateShape() { try { Console.WriteLine("Треугольник задается тремя точками"); PointCreator pointCreator = new PointCreator(); Point[] vertexes = new Point[3]; for (int i = 0; i < 3; i++) { vertexes[i] = (Point)pointCreator.CreateShape(); } return(new Triangle(vertexes)); } catch (Exception exception) { throw new Exception(exception.Message + Environment.NewLine + "Треугольник не создан"); } }
public override Shape CreateShape() { try { Console.WriteLine("Квадрат задается четырьмя точками"); PointCreator pointCreator = new PointCreator(); Point[] vertexes = new Point[4]; for (int i = 0; i < 4; i++) { vertexes[i] = (Point)pointCreator.CreateShape(); } return(new Square(vertexes)); } catch (Exception exception) { throw new Exception(exception.Message + Environment.NewLine + "Квадрат не создан"); } }
public override Shape CreateShape() { try { Console.WriteLine("Круг задается точкой центра (X, Y) и радиусом R"); PointCreator pointCreator = new PointCreator(); Point p = (Point)pointCreator.CreateShape(); double r = 0; bool isSuccessR = false; while (!isSuccessR) { Console.WriteLine("Введите R"); isSuccessR = double.TryParse(Console.ReadLine(), out r); } return(new Disc(p, r)); } catch (Exception exception) { throw new Exception(exception.Message + Environment.NewLine + "Круг не создан"); } }
public override Shape CreateShape() { try { Console.WriteLine("Выберите способ задания прямой"); Console.WriteLine("1. Пара точек"); Console.WriteLine("2. Уравнение прямой"); int.TryParse(Console.ReadLine(), out int choice); switch (choice) { case 1: PointCreator pointCreator = new PointCreator(); Console.WriteLine("Точка (x1, y1)"); Point p1 = (Point)pointCreator.CreateShape(); Console.WriteLine("Точка (x2, y2)"); Point p2 = (Point)pointCreator.CreateShape(); return(new Line(p1, p2)); case 2: Console.WriteLine("Уравнение прямой имеет вид aX + bY + c = 0"); double a = 0; bool isSuccessA = false; while (!isSuccessA) { Console.WriteLine("Введите a"); isSuccessA = double.TryParse(Console.ReadLine(), out a); } double b = 0; bool isSuccessB = false; while (!isSuccessB) { Console.WriteLine("Введите b"); isSuccessB = double.TryParse(Console.ReadLine(), out b); } double c = 0; bool isSuccessC = false; while (!isSuccessC) { Console.WriteLine("Введите c"); isSuccessC = double.TryParse(Console.ReadLine(), out c); } return(new Line(a, b, c)); default: throw new Exception("Ничего не выбрано"); } } catch (Exception exception) { throw new Exception(exception.Message + Environment.NewLine + "Прямая не создана"); } }