static void Main(string[] args) { Console.WriteLine("ProfReynolds Demonstrator_1"); Console.WriteLine(); var triangle = new Triangle { SideLength = 123.456 }; Console.WriteLine(triangle.Description()); Console.WriteLine($"Number of Sides = {triangle.NumberOfSides}"); Console.WriteLine($"Length of the Sides = {triangle.SideLength}"); Console.WriteLine($"Perimeter of the shape = {triangle.Perimeter()}"); Console.WriteLine($"Area of the shape = {triangle.Area()}"); Console.WriteLine(); var square = new Square { SideLength = 321.654 }; Console.WriteLine(square.Description()); Console.WriteLine($"Number of Sides = {square.NumberOfSides}"); Console.WriteLine($"Length of the Sides = {square.SideLength}"); Console.WriteLine($"Perimeter of the shape = {square.Perimeter()}"); Console.WriteLine($"Area of the shape = {square.Area()}"); Console.WriteLine(); var pentagon = new Pentagon { SideLength = 1.123 }; Console.WriteLine(pentagon.Description()); Console.WriteLine($"Number of Sides = {pentagon.NumberOfSides}"); Console.WriteLine($"Length of the Sides = {pentagon.SideLength}"); Console.WriteLine($"Perimeter of the shape = {pentagon.Perimeter()}"); Console.WriteLine($"Area of the shape = {pentagon.Area()}"); Console.WriteLine(); Console.Write("Press any key to continue"); Console.ReadKey(); }
public IShape CreateShape(ShapeType shapeType) { IShape shape = null; switch(shapeType) { case ShapeType.Circle: shape = new Circle(); break; case ShapeType.Squire: shape = new Squire(); break; case ShapeType.Trangle: shape = new Trangle(); break; case ShapeType.Pentagon: shape = new Pentagon(); break; } return shape; }
public static void pent_enum_test( ) //****************************************************************************80 // // Purpose: // // PENT_ENUM_TEST tests PENT_ENUM. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 07 March 2007 // // Author: // // John Burkardt // { const int N = 10; int i; Console.WriteLine(""); Console.WriteLine("PENT_ENUM_TEST"); Console.WriteLine(" PENT_ENUM counts points in pentagons."); Console.WriteLine(""); Console.WriteLine(" N Pent(N)"); Console.WriteLine(""); for (i = 0; i <= N; i++) { Console.WriteLine(i.ToString().PadLeft(4) + " " + Pentagon.pentagon_num(i).ToString().PadLeft(6) + ""); } }
static void Main(string[] args) { /* * ProfReynolds * notice how this implements exactly like the interface */ AbstractGeometricShape myGeometricShapes; Console.WriteLine("Ethan Smith Demonstrator_3"); Console.WriteLine(); myGeometricShapes = new Triangle { SideLength = 123.456 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); myGeometricShapes = new Square() { SideLength = 321.654 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); myGeometricShapes = new Pentagon() { SideLength = 1.123 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); }
static void Main(string[] args) { IGeometricShapes myGeometricShapes; Console.WriteLine("Ethan Smith Demonstrator_3"); Console.WriteLine(); /* * ProfReynolds * this is exactly what I was looking for */ myGeometricShapes = new Triangle { SideLength = 123.456 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); myGeometricShapes = new Square() { SideLength = 321.654 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); myGeometricShapes = new Pentagon() { SideLength = 1.123 }; TellAboutTheShape(myGeometricShapes); Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); }
public static Shape chooseShape(OpenGLControl openGLControl, int _chooseIcon, Point start, Point end, float size, Color color) { Shape _chooseShape = null; /*Choose a shape */ if (start.X != -1 && start.Y != -1) { switch (_chooseIcon) { case 1: //Line _chooseShape = new Line(start, end, size, color); break; case 2: //Circle _chooseShape = new Circle(start, end, size, color); break; case 3: //Ellipse _chooseShape = new Ellipse(start, end, size, color); break; case 4: //Rectangle _chooseShape = new Rectangle(start, end, size, color); break; case 5: //Triangle _chooseShape = new Triangle(start, end, size, color); break; case 6: //Pentagon _chooseShape = new Pentagon(start, end, size, color); break; case 7: //Hexagon _chooseShape = new hexagon(start, end, size, color); break; default: break; } } /* * Save the shapes to stackShape */ if (_chooseShape != null) { if (stackShape.Count > 0) { var temp = stackShape.Pop(); /*only save shapes have different first point */ if (temp.firstPoint != _chooseShape.firstPoint) { stackShape.Push(temp); } } stackShape.Push(_chooseShape); } return(_chooseShape); }
private Hexagon[] HexConvert(Triangle[][] faces) { int faceLen = faces[0].Length / 3; int edgeLen = (int)Math.Pow(2, numSubs) - 1; int tri = (edgeLen - 1) * (edgeLen) / 2; int hexnum = 30 * edgeLen + 20 * tri; Hexagon[] sphere = new Hexagon[hexnum]; Pentagon[] verts = new Pentagon[12]; int dex = 0; int hexDex = 0; verts[dex++] = new Pentagon(faces[0][2 * faceLen].mid(), faces[0][2 * faceLen].n1.mid(), faces[0][2 * faceLen].n1.n1.mid(), faces[0][2 * faceLen].n1.n1.n1.mid(), faces[0][2 * faceLen].n1.n1.n1.n1.mid()); verts[dex++] = new Pentagon(faces[3][2 * faceLen].mid(), faces[3][2 * faceLen].n1.mid(), faces[3][2 * faceLen].n1.n1.mid(), faces[3][2 * faceLen].n1.n1.n1.mid(), faces[3][2 * faceLen].n1.n1.n1.n1.mid()); for (int i = 1; i < 18; i += 3) { verts[dex++] = new Pentagon(faces[i][0].mid(), faces[i][0].n1.mid(), faces[i][0].n1.n1.mid(), faces[i][0].n1.n1.n1.mid(), faces[i][0].n1.n1.n1.n1.mid()); i++; verts[dex++] = new Pentagon(faces[i][0].mid(), faces[i][0].n1.mid(), faces[i][0].n1.n1.mid(), faces[i][0].n1.n1.n1.mid(), faces[i][0].n1.n1.n1.n1.mid()); } for (int i = 0; i < 20; i++) { if (i % 2 == 0) { Triangle anchor = faces[i][2 * faceLen]; for (int j = 0; j < edgeLen; j++) { int rowLen = edgeLen + 1 - j; Triangle cursor = anchor; for (int k = 0; k < rowLen; k++) { if (k == 0 && i % 4 == 0) { sphere[hexDex++] = new Hexagon(cursor.mid(), cursor.n0.mid(), cursor.n0.n2.mid(), cursor.n0.n2.n1.mid(), cursor.n0.n2.n1.n1.mid(), cursor.n0.n2.n1.n1.n0.mid()); } else { sphere[hexDex++] = new Hexagon(cursor.mid(), cursor.n0.mid(), cursor.n0.n2.mid(), cursor.n0.n2.n1.mid(), cursor.n0.n2.n1.n0.mid(), cursor.n0.n2.n1.n0.n2.mid()); } cursor = cursor.n0.n1; } anchor = anchor.n0.n2; } } else { Triangle anchor = faces[i][2 * faceLen].n0; for (int j = 0; j < edgeLen; j++) { int rowLen = j + 1; Triangle cursor = anchor; for (int k = 0; k < rowLen; k++) { if (k == 0 && i % 4 == 3) { sphere[hexDex++] = new Hexagon(cursor.mid(), cursor.n1.mid(), cursor.n1.n2.mid(), cursor.n1.n2.n2.mid(), cursor.n1.n2.n2.n0.mid(), cursor.n1.n2.n2.n0.n1.mid()); } else { sphere[hexDex++] = new Hexagon(cursor.mid(), cursor.n1.mid(), cursor.n1.n2.mid(), cursor.n1.n2.n0.mid(), cursor.n1.n2.n0.n1.mid(), cursor.n1.n2.n0.n1.n2.mid()); } cursor = cursor.n2.n1; } anchor = anchor.n1.n0; } } } return(sphere); }
public void Verify_Total_Sum_Of_Angles_Can_Be_Retrieved() { Pentagon pentagon = new Pentagon(); pentagon.TotalMeasureOfAllAngles().ShouldBe(180); }
public void Verify_That_Number_Of_Sides_Is_5() { Pentagon pentagon = new Pentagon(); pentagon.NumberOfSides.ShouldBe(5); }
public void TestPentagonDeserealization() { Pentagon p = Pentagon.Deserialize("serializeTest.xml"); Assert.IsTrue(p != null); }
public string Describe(Pentagon shape) => "Looks kind of like a house.";
/// <summary> Creates an element and sets the corresponding properties. </summary> /// <param name="symbol"> Symbol type of the element. </param> /// <param name="color"> Color of the element. </param> /// <param name="stroke"> Stroke of the element. </param> /// <returns> The created element. </returns> private static FrameworkElement CreateElement(Symbols symbol, Color color, Color stroke) { FrameworkElement frameworkElement = null; switch (symbol) { case Symbols.Ball: frameworkElement = new Ball { Color = color, Stroke = stroke, ToolTip = "Ball" }; break; case Symbols.Cube: frameworkElement = new Cube { Color = color, Stroke = stroke, ToolTip = "Cube" }; break; case Symbols.Diamond: frameworkElement = new Diamond { Color = color, Stroke = stroke, ToolTip = "Diamond" }; break; case Symbols.Hexagon: frameworkElement = new Hexagon { Color = color, Stroke = stroke, ToolTip = "Hexagon" }; break; case Symbols.Pentagon: frameworkElement = new Pentagon { Color = color, Stroke = stroke, ToolTip = "Pentagon" }; break; case Symbols.Pin: frameworkElement = new Pin { Color = color, ToolTip = "Pin" }; break; case Symbols.Pyramid: frameworkElement = new Pyramid { Color = color, Stroke = stroke, ToolTip = "Pyramid" }; break; case Symbols.Star: frameworkElement = new Star { Color = color, Stroke = stroke, ToolTip = "Star" }; break; case Symbols.TriangleDown: frameworkElement = new TriangleDown { Color = color, Stroke = stroke, ToolTip = "TriangleDown" }; break; case Symbols.TriangleUp: frameworkElement = new TriangleUp { Color = color, Stroke = stroke, ToolTip = "TriangleUp" }; break; case Symbols.Truck: frameworkElement = new Truck { Color = color, ToolTip = "Truck" }; break; } if (frameworkElement == null) { return(null); } frameworkElement.Height = 32; frameworkElement.Width = 32; return(frameworkElement); }
static void Main(string[] args) { #region StartUpConfig bool runApp = true; bool shapeSelect = true; string usersInput = ""; double dimension; bool triangleType = false; //true if 90 degrees, false if otherwise Rectangle rectangle = null; RectangularPrism rp = null; Square square = null; Cube cube = null; Circle circle = null; Sphere sphere = null; Triangle triangle = null; Octagon octagon = null; Hexagon hexagon = null; Pentagon pentagon = null; // make sure to include any new shapes into the shapeList array string[] shapeList = { "Rectangle", "Rectangular Prism", "Square", "Cube", "Circle", "Sphere", "Triangle", "Octagon", "Hexagon", "Pentagon" }; #endregion Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("============================================"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Shape Area Calculator"); while (runApp == true) { if (shapeSelect == false) { shapeSelect = true; } Console.Write("Enter a supported shape or a command (type \""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("/help"); Console.ForegroundColor = ConsoleColor.White; Console.Write("\" to see commands)\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine().ToLower(); Console.WriteLine(); if (usersInput == "/shapes" || usersInput == "/s") { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; // Lists out all the shapes as long as they are included in the shapeList shapeList.ToList().ForEach(i => Console.WriteLine(i)); Console.WriteLine(); } else if (usersInput == "/help" || usersInput == "/h") { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.Write("\""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("/shapes"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\" : shows a list of all supported shapes"); Console.Write("\""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("/quit"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\" : exit the program"); Console.Write("\""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("shapename"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\" : begins the process to gather area for shape\n"); } else if (usersInput == "/quit" || usersInput == "/q") { runApp = false; } else if (usersInput == "shapename") { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.Write("shapename is an invalid command\ntry entering an actual shape name such as \""); Console.ForegroundColor = ConsoleColor.Green; Console.Write("circle"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\"\n"); } else { Console.Clear(); while (shapeSelect == true) { switch (usersInput) // SWITH CASE FOR ALL SUPPORTED SHAPES TO CALCULATE THE AREA GOES HERE { #region Rectangle case "rectangle": try { if (rectangle == null) { rectangle = new Rectangle(); } Console.WriteLine("Rectangle\n"); Console.Write("Enter length:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { rectangle.setLength(dimension); // Set Rectangle shapes length Console.Write("\nEnter height:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { rectangle.setHeight(dimension); // Set Rectangle shapes height Console.WriteLine(""); Console.WriteLine("Area: {0}", rectangle.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "rectangle"; } } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "rectangle"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "rectangle"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Square case "square": try { if (square == null) { square = new Square(); } Console.WriteLine("Square\n"); Console.Write("Enter length or width:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { square.setLength(dimension); // Set Square shapes length square.setHeight(dimension); // Set Square shapes height Console.WriteLine(""); Console.WriteLine("Area: {0}", square.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "square"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "square"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Cube case "cube": try { if (cube == null) { cube = new Cube(); } Console.WriteLine("Cube\n"); Console.Write("Enter edge(a length):\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { cube.setEdge(dimension); // Set Cube shapes edge Console.WriteLine(""); Console.WriteLine("Volume: {0}", cube.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "cube"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "cube"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Circle case "circle": try { if (circle == null) { circle = new Circle(); } Console.WriteLine("Circle\n"); Console.Write("Enter radius:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { circle.setRadius(dimension); // Set Circle shapes radius Console.WriteLine(""); Console.WriteLine("Area: {0}", circle.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "circle"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "circle"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Sphere case "sphere": try { if (sphere == null) { sphere = new Sphere(); } Console.WriteLine("Sphere\n"); Console.Write("Enter radius:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { sphere.setRadius(dimension); // Set Sphere shapes radius Console.WriteLine(""); Console.WriteLine("Volume: {0}", sphere.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "sphere"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "sphere"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Triangle case "triangle": try { if (triangle == null) { triangle = new Triangle(); } Console.WriteLine("Triangle\n"); Console.Write("90 Degree angle triangle? Please enter: "); Console.ForegroundColor = ConsoleColor.Green; Console.Write("yes "); Console.ForegroundColor = ConsoleColor.White; Console.Write("or "); Console.ForegroundColor = ConsoleColor.Green; Console.Write("no"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("\n\n> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine().ToLower(); Console.WriteLine(); if (usersInput == "yes") { triangleType = true; Console.Write("Enter base:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { triangle.setBase(dimension); // Set Triangle shapes base Console.Write("\nEnter height:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { triangle.setHeight(dimension); // Set Triangle shapes height Console.WriteLine(""); Console.WriteLine("Area: {0}", triangle.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Number must be greater than 0\n"); usersInput = "triangle"; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Number must be greater than 0\n"); usersInput = "triangle"; } } else if (usersInput == "no") { triangleType = false; Console.Write("Enter base:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { triangle.setBase(dimension); // Set Triangle shapes base Console.Write("\nEnter side length:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { triangle.setSide(dimension); // Set Triangle shapes side Console.Write("\nEnter angle(degrees):\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { triangle.setAngle(dimension); // Set Triangle shapes angle Console.WriteLine(""); Console.WriteLine("Area: {0}", triangle.getAreaWithAngle()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Number must be greater than 0\n"); usersInput = "triangle"; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Number must be greater than 0\n"); usersInput = "triangle"; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Number must be greater than 0\n"); usersInput = "triangle"; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("ERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Invalid Input\n"); usersInput = "triangle"; // sets the userInput to triangle to put the user back into trying to get the area for triangle } } catch (FormatException) // This catchs if they enter a string { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Invalid Input\n"); usersInput = "triangle"; } catch (Exception) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\nERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Octagon case "octagon": try { if (octagon == null) { octagon = new Octagon(); } Console.WriteLine("Octagon\n"); Console.Write("Enter side:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { octagon.setSide(dimension); // Set Octagon shapes side length Console.WriteLine(""); Console.WriteLine("Area: {0}", octagon.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "octagon"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "octagon"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Hexagon case "hexagon": try { if (hexagon == null) { hexagon = new Hexagon(); } Console.WriteLine("Hexagon\n"); Console.Write("Enter side:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { hexagon.setSide(dimension); // Set Hexagon shapes side length Console.WriteLine(""); Console.WriteLine("Area: {0}", hexagon.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "hexagon"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "hexagon"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region Pentagon case "pentagon": try { if (pentagon == null) { pentagon = new Pentagon(); } Console.WriteLine("Pentagon\n"); Console.Write("Enter side:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { pentagon.setSide(dimension); // Set Pentagon shapes side length Console.WriteLine(""); Console.WriteLine("Area: {0}", pentagon.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "pentagon"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "pentagon"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion #region RectangularPrism case "rectangular prism": try { if (rp == null) { rp = new RectangularPrism(); } Console.WriteLine("Rectangular Prism\n"); Console.Write("Enter length:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { rp.setLength(dimension); // Set RP shapes length Console.Write("\nEnter width:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { rp.setWidth(dimension); // Set RP shapes width Console.Write("\nEnter height:\n\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; usersInput = Console.ReadLine(); dimension = Convert.ToDouble(usersInput); // Parse Input to Double if (dimension > 0) { rp.setHeight(dimension); // Set RP shapes height Console.WriteLine(""); Console.WriteLine("Volume: {0}", rp.getArea()); // Output the Area Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("--------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; shapeSelect = false; // Exits the shape selection loop } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "rectangular prism"; } } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "rectangular prism"; } } else { Console.WriteLine("\nERROR: Number must be greater than 0\n"); usersInput = "rectangular prism"; } } catch (FormatException) // This catchs if they enter a string { Console.WriteLine("\nERROR: Must enter a valid number\n"); usersInput = "rectangular prism"; } catch (Exception) { Console.WriteLine("\nERROR: Unidentified error, returning you to main page\n"); shapeSelect = false; } break; #endregion default: Console.ForegroundColor = ConsoleColor.Red; Console.Write("ERROR"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(": Invalid Input\n"); shapeSelect = false; break; // Note: Setting the shapeSelect to false to avoid infinite loops. } } } } }
public void Verify_The_Description_Returns_Value() { var pentagon = new Pentagon(); pentagon.Description().ShouldNotBeNullOrWhiteSpace(); }
protected override INode CreateFigure(MemoShape model) { var ret = default(INode); switch (model.Kind) { case MemoShapeKind.RoundRect: { ret = new RoundedRect(); break; } case MemoShapeKind.Triangle: { ret = new Triangle(); break; } case MemoShapeKind.Ellipse: { ret = new Ellipse(); break; } case MemoShapeKind.Diamond: { ret = new Diamond(); break; } case MemoShapeKind.Parallelogram: { ret = new Parallelogram(); break; } case MemoShapeKind.Cylinder: { ret = new Cylinder(); break; } case MemoShapeKind.Paper: { ret = new Paper(); break; } case MemoShapeKind.LeftArrow: { ret = new ArrowFigure(Directions.Left); break; } case MemoShapeKind.RightArrow: { ret = new ArrowFigure(Directions.Right); break; } case MemoShapeKind.UpArrow: { ret = new ArrowFigure(Directions.Up); break; } case MemoShapeKind.DownArrow: { ret = new ArrowFigure(Directions.Down); break; } case MemoShapeKind.LeftRightArrow: { ret = new TwoHeadArrowFigure(false); break; } case MemoShapeKind.UpDownArrow: { ret = new TwoHeadArrowFigure(true); break; } case MemoShapeKind.Pentagon: { ret = new Pentagon(); break; } case MemoShapeKind.Chevron: { ret = new Chevron(); break; } case MemoShapeKind.Equal: { ret = new EqualFigure(false); break; } case MemoShapeKind.NotEqual: { ret = new EqualFigure(true); break; } case MemoShapeKind.Plus: { ret = new PlusFigure(); break; } case MemoShapeKind.Minus: { ret = new MinusFigure(); break; } case MemoShapeKind.Times: { ret = new TimesFigure(); break; } case MemoShapeKind.Devide: { ret = new DevideFigure(); break; } case MemoShapeKind.Rect: default: { ret = new Rect(); break; } } ret.BorderWidth = 1; ret.Background = new GradientBrushDescription( Color.FromArgb(230, 240, 255), Color.FromArgb(200, 220, 240), 90f ); ret.Foreground = Color.FromArgb(75, 125, 190); ret.MinSize = new Size(16, 16); //ret.AutoSizeKinds = AutoSizeKinds.GrowBoth; return(ret); }
static void Main(string[] args) { Shape[] shapes1 = new Shape[3]; shapes1[0] = new Square(5, "red"); shapes1[1] = new Circle(5, "blue"); shapes1[2] = new Pentagon(5, "green"); Shape[] shapes2 = new Shape[2]; shapes2[0] = new Square(10, "amber"); shapes2[1] = new Pentagon(3, "brown"); Console.WriteLine("FOREACH SHAPES"); Shapes shapeCollection = new Shapes(shapes1); int i = 0; foreach (Shape s in shapeCollection) { Console.WriteLine(i + " " + s.Color); ++i; } ComparableShapes compShapes = new ComparableShapes(); try { compShapes = new ComparableShapes(shapes2); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } Console.WriteLine("FOREACH COMPARABLESHAPES"); i = 0; foreach (Shape s in compShapes) { Console.WriteLine(i + " " + s.Color); ++i; } Console.WriteLine("SHOULD THROW AN EXCEPTION: INSTANTIATING USING INCOMPARABLE OBJECTS"); try { ComparableShapes compShapes2 = new ComparableShapes(shapes1); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } Console.WriteLine("SHOULD THROW AN EXCEPTION: INSERTING CIRCLE"); Circle c = new Circle(4, "white"); try { compShapes.insertIntoArray(c, 1); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } }
public void Verify_That_TotalMeasureOfAngles_Is_540() { Pentagon pentagon = new Pentagon(); pentagon.TotalMeasureOfAllAngles().ShouldBe(540); }
private void btBrowse_Click(object sender, EventArgs e) { tbFile.Text = ""; lbOutput.Items.Clear(); OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "*.csv | *.*"; dialog.InitialDirectory = Directory.GetCurrentDirectory().ToString(); dialog.Title = "Select CSV File"; if (dialog.ShowDialog() == DialogResult.OK) { string filename = dialog.FileName; tbFile.Text = filename; var reader = new System.IO.StreamReader(File.OpenRead(filename)); List<string> listA = new List<string>(); List<string> listB = new List<string>(); while (!reader.EndOfStream) { string line = reader.ReadLine(); string output = "Default"; if(line.Equals("")) { output = "No Data Found"; } else { var values = line.Split(','); string shape = values[0]; string length = values[1]; double n; bool isNumeric = double.TryParse(length, out n); if (isNumeric) { switch (shape) { case "circle": Circle c = new Circle(length); output = c.GetOutput(); break; case "triangle": Triangle t = new Triangle(length); output = t.GetOutput(); break; case "square": Square s = new Square(length); output = s.GetOutput(); break; case "pentagon": Pentagon p = new Pentagon(length); output = p.GetOutput(); break; default: // You can use the default case. output = "Shape " + shape + " is not a valid shape"; break; } } else output = "Shape " + shape + " does not have a numeric value ( " + length + " )"; } lbOutput.Items.Add(output); } } }
private void Clicks(object sender, MouseButtonEventArgs e) { GetMousePosition(); currentActiviti.Content = "Choose " + (clicks.Count + 1) + " point"; if (method == -1) { currentActiviti.Content = "Choose shape"; } else if (clicks.Count == 2 && method == 0) { double r = Math.Sqrt(Math.Pow(clicks[0].X - clicks[1].X, 2) + Math.Pow(clicks[0].Y - clicks[1].Y, 2)); Circle circle = new Circle(clicks[0], r); ListBoxItem itm = new ListBoxItem(); itm.Content = "Circle Center: " + clicks[0] + " Radius: " + r; Shapes.Items.Add(itm); currentActiviti.Content = "Tadow!"; method = -1; clicks.Clear(); } else if (clicks.Count == 3 && method == 1) { Triangle traingle = new Triangle(); traingle.point1 = clicks[0]; traingle.point2 = clicks[1]; traingle.point3 = clicks[2]; traingle.Make(); ListBoxItem itm = new ListBoxItem(); itm.Content = "Triangle Point A: " + clicks[0] + " Point B: " + clicks[1] + " Point C: " + clicks[2]; Shapes.Items.Add(itm); currentActiviti.Content = "Tadow!"; method = -1; clicks.Clear(); } else if (clicks.Count == 4 && method == 2) { Rectangle rectangle = new Rectangle(); rectangle.point1 = clicks[0]; rectangle.point2 = clicks[1]; rectangle.point3 = clicks[2]; rectangle.point4 = clicks[3]; rectangle.Make(); ListBoxItem itm = new ListBoxItem(); itm.Content = "Rectangle Point A: " + clicks[0] + " Point B: " + clicks[1] + " Point B: " + clicks[1] + " Point B: " + clicks[1]; Shapes.Items.Add(itm); currentActiviti.Content = "Tadow!"; method = -1; clicks.Clear(); } else if (clicks.Count == 5 && method == 3) { Pentagon pentagon = new Pentagon(clicks[0], clicks[1], clicks[2], clicks[3], clicks[4]); ListBoxItem itm = new ListBoxItem(); itm.Content = "Pentagon Point A: " + clicks[0] + " Point B: " + clicks[1] + " Point C: " + clicks[2] + " Point D: " + clicks[3] + " Point E: " + clicks[4]; Shapes.Items.Add(itm); currentActiviti.Content = "Tadow!"; method = -1; clicks.Clear(); } }
public static void i4_partition_count(int n, ref int[] p) //****************************************************************************80 // // Purpose: // // I4_PARTITION_COUNT computes the number of partitions of an integer. // // Discussion: // // Partition numbers are difficult to compute. This routine uses // Euler's method, which observes that: // // P(0) = 1 // P(N) = P(N-1) + P(N-2) // - P(N-5) - P(N-7) // + P(N-12) + P(N-15) // - ... // // where the numbers 1, 2, 5, 7, ... to be subtracted from N in the // indices are the successive pentagonal numbers, (with both positive // and negative indices) with the summation stopping when a negative // index is reached. // // First values: // // N P // // 0 1 // 1 1 // 2 2 // 3 3 // 4 5 // 5 7 // 6 11 // 7 15 // 8 22 // 9 30 // 10 42 // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 May 2003 // // Author: // // John Burkardt // // Reference: // // John Conway, Richard Guy, // The Book of Numbers, // Springer Verlag, 1996, page 95. // // Parameters: // // Input, int N, the index of the highest partition number desired. // // Output, int P[N+1], the partition numbers. // { int i; p[0] = 1; for (i = 1; i <= n; i++) { p[i] = 0; int j = 0; int sgn = 1; int pj; for (;;) { j += 1; pj = Pentagon.pentagon_num(j); if (i < pj) { break; } p[i] += sgn * p[i - pj]; sgn = -sgn; } j = 0; sgn = 1; for (;;) { j -= 1; pj = Pentagon.pentagon_num(j); if (i < pj) { break; } p[i] += sgn * p[i - pj]; sgn = -sgn; } } }