public override void Run() { switch (Operation) { case "rect": Result = Rect.Area(); break; case "square": Result = Rect.Area(); break; case "triangle": Result = Triangl.Area(Formula); break; case "circle": Result = Circl.Area(); break; case "trapezoid": Result = Trapez.Area(); break; case "polygon": Result = Polyg.Area(); break; } }
static void Main(string[] args) { bool inputError; int UserInputSideA; do { inputError = false; try { List <GeometriForm> sqList = new List <GeometriForm>(); GeometriForm sq = new Square(10); sqList.Add(sq); GeometriForm rec = new Rectangular(10, 5); sqList.Add(rec); GeometriForm paral = new Parallelogram(3, 5, 20); sqList.Add(paral); GeometriForm trapez = new Trapez(10, 9, 8, 9); sqList.Add(trapez); GeometriForm triangle = new Triangle(10, 5, 2); sqList.Add(triangle); foreach (GeometriForm item in sqList) { Console.WriteLine("Type: " + item.ToString()); Console.WriteLine("The perimeter of the square is: " + item.GetPerimiter()); Console.WriteLine("The area of the square is: " + item.GetArea()); Console.WriteLine("___________________________________________"); Console.WriteLine(); } Console.ReadKey(); } catch (Exception) { Console.WriteLine("Not a valid input try again:"); inputError = true; } } while (inputError); }
public static Trapez Parse(SqlString s) { string value = s.Value; if (s.IsNull) { return(Null); } if (s.Value.Split(".".ToCharArray()).Length > 1) { throw new ArgumentException("Użyj przecinków zamiast kropek"); } string[] dane = s.Value.Split(" ".ToCharArray()); if (dane.Length < 8) { throw new ArgumentException("Za mała ilość argumentów"); } double ax = double.Parse(dane[0]); double ay = double.Parse(dane[1]); double bx = double.Parse(dane[2]); double by = double.Parse(dane[3]); double cx = double.Parse(dane[4]); double cy = double.Parse(dane[5]); double dx = double.Parse(dane[6]); double dy = double.Parse(dane[7]); Trapez tmp = new Trapez(ax, ay, bx, by, cx, cy, dx, dy); if (!tmp.SprawdzPunkty()) { throw new ArgumentException("Podane punkty nie tworzą trapezu - " + "pamiętaj, podaj wartości z kolejnych wierzchołków."); } return(tmp); }