public static void Factory_with_InRadius_Creates_Shape() { Octagon octagon = Octagon.OctagonByInradius(9.238795325); Assert.AreEqual(numberOfSides, octagon.Points.Count); Assert.AreEqual(numberOfSides, octagon.Angles.Count); Assert.AreEqual(numberOfSides, octagon.Sides.Count); Assert.AreEqual(GeometryLibrary.ZeroTolerance, octagon.Tolerance); Assert.AreEqual(0, octagon.Centroid.X, Tolerance); Assert.AreEqual(0, octagon.Centroid.Y, Tolerance); Assert.AreEqual(numberOfSides, octagon.NumberOfSides); Assert.AreEqual(7.653668647, octagon.SideLength, Tolerance); Assert.AreEqual(10, octagon.CircumRadius, Tolerance); Assert.AreEqual(0, octagon.CircumCenter.X, Tolerance); Assert.AreEqual(0, octagon.CircumCenter.Y, Tolerance); Assert.AreEqual(9.238795325, octagon.Apothem, Tolerance); Assert.AreEqual(9.238795325, octagon.InRadius, Tolerance); Assert.AreEqual(0, octagon.InCenter.X, Tolerance); Assert.AreEqual(0, octagon.InCenter.Y, Tolerance); Assert.AreEqual(135, octagon.AngleInterior.Degrees, Tolerance); Assert.AreEqual(1080, octagon.AngleInteriorSum.DegreesRaw, Tolerance); }
public bool Compare(Octagon otherObject) { if (this.Equals(otherObject)) { return(true); } return(false); }
public void TestMethod4() { Octagon test = new Octagon(100, 100, new Vector2(100, 100)); bool expected = true; bool actual = test.Equals(oct); Assert.AreEqual(expected, actual); }
public static void Main(string[] args) { var square = new Square(5); DisplayPoligon("Square", square); var triangle = new Triangle(5); DisplayPoligon("Triangle", triangle); var octagon = new Octagon(5); DisplayPoligon("Octagon", octagon); }
private void RemoveWalls(GameObject gameObjectRef, Octagon octagon) { var walls = GetWalls(gameObjectRef); foreach (var wall in walls) { // Check to see if this wall is in the list of this octagons walls.. If not, turn it off var wallName = wall.name.Split('-')[0]; var wallNameEnum = (Enumerations.Wall)Enum.Parse(typeof(Enumerations.Wall), wallName); if (!octagon.Walls.Contains(wallNameEnum)) { wall.gameObject.SetActive(false); } } }
static void Main(string[] args) { var Square = new Square(5); DisplayPolygon("Square", Square); var Triangle = new Triangle(5); DisplayPolygon("Triangle", Triangle); var Octagon = new Octagon(5); DisplayPolygon("Octagon", Octagon); Console.ReadLine(); }
private void RemoveWalls(GameObject gameObjectRef, Octagon octagon) { var walls = GetWalls(gameObjectRef); foreach (var wall in walls) { // Check to see if this wall is in the list of this octagons walls.. If not, turn it off var wallName = wall.name.Split('-')[0]; var wallNameEnum = (Enumerations.Wall)Enum.Parse(typeof(Enumerations.Wall), wallName); if (!octagon.Walls.Contains(wallNameEnum)) { wall.gameObject.GetComponent <Image>().sprite = NonWallSprite; wall.gameObject.GetComponent <WallScript>().active = false; } } }
public static void GeometricFiguresDisplay() { var square = new Square(5); DisplayPolygon("Cuadrado", square); var triangle = new Triangle(5); DisplayPolygon("Triángulo", triangle); var octagon = new Octagon(5); DisplayPolygon("Octágono", octagon); Console.Read(); }
static void Main(string[] args) { //TODO: 05 - Llamo a la clase concreta Square //var square = new Square(5); //DisplayPolygon("Square", square); //TODO: 10 - Llame a Triangle clase que hereda de la clase abstracta AbstractRegularPolygon //var triangle = new Triangle(5); //DisplayPolygon("Triangle", triangle); //TODO: 13 - Llamo al Octagono que implementa la interface IRegularPolygon octagon = new Octagon(5); DisplayPolygon("Octagon", octagon); Console.Read(); }
public void AddRoom(Room r) { if (r is Square) { posRooms[rInitialized] = r.PosRoom; rInitialized++; } else if (r is RectangleV) { RectangleV auxRectangleV = (RectangleV)r; for (int i = 0; i <= 1; i++) { posRooms[rInitialized] = auxRectangleV.posSubRooms[i]; rInitialized++; } } else if (r is RectangleH) { RectangleH auxRectangleH = (RectangleH)r; for (int i = 0; i <= 1; i++) { posRooms[rInitialized] = auxRectangleH.posSubRooms[i]; rInitialized++; } } else if (r is Triangle) { Triangle auxTriangle = (Triangle)r; posRooms[rInitialized] = auxTriangle.PosRoom; rInitialized++; for (int i = 0; i <= 3; i++) { if (!auxTriangle.PrevRoom[i]) { posNoCorr[nCInitialized] = auxTriangle.PosCorridors[i]; nCInitialized++; } } } else if (r is HexagonalV) { HexagonalV auxHexagonalV = (HexagonalV)r; for (int i = 0; i <= 5; i++) { posRooms[rInitialized] = auxHexagonalV.PosSubRooms[i]; rInitialized++; } for (int i = 0; i <= 7; i++) { posNoCorr[nCInitialized] = auxHexagonalV.PosCorridors[i]; nCInitialized++; } } else if (r is HexagonalH) { HexagonalH auxHexagonalH = (HexagonalH)r; for (int i = 0; i <= 5; i++) { posRooms[rInitialized] = auxHexagonalH.PosSubRooms[i]; rInitialized++; } for (int i = 0; i <= 7; i++) { posNoCorr[nCInitialized] = auxHexagonalH.PosCorridors[i]; nCInitialized++; } } else if (r is Octagon) { Octagon auxOctagon = (Octagon)r; for (int i = 0; i <= 8; i++) { posRooms[rInitialized] = auxOctagon.PosSubRooms[i]; rInitialized++; } for (int i = 0; i <= 7; i++) { posNoCorr[nCInitialized] = auxOctagon.PosCorridors[i]; nCInitialized++; } } else { Square2 auxSquare2 = (Square2)r; for (int i = 0; i <= 3; i++) { posRooms[rInitialized] = auxSquare2.PosSubRooms[i]; rInitialized++; } } rooms.Add(r); roomCounter++; }
public static void Main() { Hexagon hex = new Hexagon("James"); Circle c = new Circle("Lisa"); IPointy itfPt = null; try { // dynamic test if interface is supported. itfPt = (IPointy) c; Console.WriteLine(itfPt.Points); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } // or use "as" keyword to see interfaces supported. Hexagon hex2 = new Hexagon("Peter"); IPointy itfPt2 = hex2 as IPointy; if (itfPt2 != null) Console.WriteLine("YES! Points: {0}", itfPt2.Points); else Console.WriteLine("OOPS! Not pointy..."); // or check for implemented interface using "is" keyword Shape[] shapes = { new Hexagon(), new Circle(), new Triangle("Joe"), new Triangle("JoJo")}; for (int i = 0; i < shapes.Length; i++) { shapes[i].Draw(); // who's pointy if (shapes[i] is IPointy) { Console.WriteLine("-> Points: {0}", ((IPointy) shapes[i]).Points); } else { Console.WriteLine("-> {0} is not pointy!", shapes[i].PetName); } } IPointy[] pointies = { new Hexagon(), new Knife(), new Triangle(), new Fork(), new PitchFork()}; foreach (IPointy i in pointies) { Console.WriteLine("Object has {0} points.", i.Points); } // resolving name clashes Octagon oct = new Octagon(); IDrawToForm ifrm = (IDrawToForm) oct; ifrm.Draw(); IDrawToMemory imem = (IDrawToMemory) oct; imem.Draw(); IDrawToPrinter iprt = (IDrawToPrinter) oct; iprt.Draw(); // must use casting to access the interface method ((IDrawToPrinter)oct).Draw(); if (oct is IDrawToMemory) { ((IDrawToMemory)oct).Draw(); } // using BitmapImage invoke each method at object level // as well as extract reference to supported interface BitmapImage bm = new BitmapImage(); bm.Draw(); bm.DrawInBoundingBox(10, 10, 100, 150); bm.DrawUpsideDown(); // get IAdvancedDraw explicitly IAdvancedDraw iad = bm as IAdvancedDraw; if (iad != null) { iad.DrawUpsideDown(); } // multiple inheritance Snickerdoodle sn = new Snickerdoodle(); sn.Draw(); sn.Print(); Muffin mf = new Muffin(); ((IDrawable)mf).Draw(); ((IPrintable)mf).Draw(); mf.Print(); mf.GetNumberOfSides(); }
// Use this for initialization void Awake() { currentRooms = roomsInCritPath; Octagon o = new Octagon(Vector2.zero, Random.Range(minRoomSize, maxRoomSize), Random.Range(minSideCoef, maxSideCoef), walls); o.transform.parent = transform; while (currentRooms > 0) { Octagon z = new Octagon(new Vector2(o.transform.position.x, o.transform.position.y) + NextRoomLocation(), Random.Range(minRoomSize, maxRoomSize), Random.Range(minSideCoef, maxSideCoef), walls); z.transform.parent = transform; Path(new Vector2(o.transform.position.x, o.transform.position.y), new Vector2(z.transform.position.x, z.transform.position.y)); if (Random.value > 0.2) { int rando = (int)Mathf.Floor(Random.Range(0, 3)); //left if (rando == 0) { Octagon deadend = new Octagon(new Vector2(z.transform.position.x, z.transform.position.y) + new Vector2(-Random.Range(minDistance, maxDistance), 0), Random.Range(minRoomSize, maxRoomSize), Random.Range(minSideCoef, maxSideCoef), walls); deadend.transform.parent = transform; Path(new Vector2(z.transform.position.x, z.transform.position.y), new Vector2(deadend.transform.position.x, deadend.transform.position.y)); } //right if (rando == 1) { Octagon deadend = new Octagon(new Vector2(z.transform.position.x, z.transform.position.y) + new Vector2(Random.Range(minDistance, maxDistance), 0), Random.Range(minRoomSize, maxRoomSize), Random.Range(minSideCoef, maxSideCoef), walls); deadend.transform.parent = transform; Path(new Vector2(z.transform.position.x, z.transform.position.y), new Vector2(deadend.transform.position.x, deadend.transform.position.y)); } if (rando > chanceOf2MaggotsInRoom) { Instantiate(maggot, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); Instantiate(maggot, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); numberOfEnemies += 2; } else if (rando > chanceOf1MaggotInRoom) { Instantiate(maggot, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); numberOfEnemies++; } if (rando < chanceOf2BloodVessel) { Instantiate(bloodVessel, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); Instantiate(bloodVessel, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); numberOfVessels += 2; } else if (rando < chanceOf1BloodVessel) { Instantiate(bloodVessel, new Vector3(z.transform.position.x + Random.Range(-1, 1) + 1000, z.transform.position.y + Random.Range(-1, 1), 0), Quaternion.Euler(0, 0, Random.Range(0, 360))); numberOfVessels++; } } o = z; currentRooms--; } Mesh mesh = new Mesh(); GameObject t = Instantiate(tick, Vector3.zero, Quaternion.identity) as GameObject; GameObject controlsGameObj = Instantiate(controls, Vector3.zero, Quaternion.identity) as GameObject; t.SetActive(true); }
public static void MainMenu() { WriteLine("Welcome to the Math assignment in C Sharp!"); WriteLine("Enter 1 to build a rectangle, 2 for a square, 3 for a triangle, 4 for an octagon or 5 for a times table."); WriteLine("Or enter 0 to exit."); var answer = ReadLine(); if (answer == "0") { WriteLine("Goodbye!"); Environment.Exit(0); } else if (answer == "1") { WriteLine("Enter the length of your rectangle: "); double length = 0; double width = 0; try { length = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error! Invalid value. Going back to main menu..."); Menu.MainMenu(); } WriteLine("Enter the width of your rectangle: "); try { width = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error! Invalid value. Going back to main menu..."); Menu.MainMenu(); } Rectangle rectangle = new Rectangle(length, width); WriteLine("The area of your rectangle is " + rectangle.GetArea()); rectangle.AcceptDetails(); rectangle.Display(); rectangle.DisplayInfo(); Menu.MainMenu(); } else if (answer == "2") { WriteLine("Enter the length and width of your square: "); double length = 0; try { length = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error. Invalid value specified. Returning to main menu..."); Menu.MainMenu(); } var width = length; Square square = new Square(length, width); WriteLine("The area of your rectangle is " + square.GetArea()); square.AcceptDetails(); square.Display(); Menu.MainMenu(); } else if (answer == "3") { WriteLine("Enter the length of your triangle: "); double length = 0; double width = 0; try { length = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error! Invalid value. Going back to main menu..."); Menu.MainMenu(); } WriteLine("Enter the width of your triangle: "); try { width = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error! Invalid value. Going back to main menu..."); Menu.MainMenu(); } Triangle triangle = new Triangle(length, width); WriteLine("The area of your triangle is " + triangle.GetArea()); triangle.AcceptDetails(); triangle.Display(); Menu.MainMenu(); } else if (answer == "4") { WriteLine("Enter the side length of your octagon: "); double sidelength = 0; try { sidelength = Convert.ToDouble(ReadLine()); } catch (SystemException) { WriteLine("Error! Invalid value. Going back to main menu..."); Menu.MainMenu(); } Octagon octagon = new Octagon(sidelength); octagon.AcceptDetails(); octagon.Display(); Menu.MainMenu(); } else if (answer == "5") { WriteLine("Please enter your value for a times table."); double value = 0; try { value = Convert.ToDouble(ReadLine()); } catch (SystemException) { } TimesTable table = new TimesTable(value); table.Display(); Menu.MainMenu(); } else { WriteLine("Invalid response! Try again."); Menu.MainMenu(); } }
static void Main(string[] args) { Triangle triangle = new Triangle(5); int numOfSides = triangle.NumberOfSides; // I have access to abstract properties (if public) // no access to private properties in abstract/base class triangle.MayOverwrite(); // I can still call abstract method even though not overwritten in child Octagon octagon = new Octagon(10); //IPersonRepository repo = new WebServiceRepository(); //var people = repo.GetPeople(); // I can use CSV repository instead easily // the code is exacly the same as above // without any changes //repo = new CSVRepository(); //people = repo.GetPeople(); //repo = new SQLRepository(); //people = repo.GetPeople(); // To refactor for (WebServiceRepo, CSV, SQLRepository) we will use Factory Method (RepositoryFactory class) // Compile time Factory -> application makes decision what repo to use // References to ALL repos have to be here (better to use Run-Time Binding (using reflection)) // This allows us to NOT have references to all repos IPersonRepository repoFromFactory = RepositoryFactory.GetRepository("SQL"); repoFromFactory.GetPeople(); // TAKE TWO // Dynamic Loading // 1. Get Type and assembly from configuration // 2. Load assembly through reflection // 3. Create Repository instance with the Activator // This allows us to get repository without specifying Repo type IPersonRepository repoFromDynamicRepository = RepositoryFactoryDynamic.GetRepository(); var people = repoFromDynamicRepository.GetPeople(); // TAKE THREE -> UNIT TESTING // Need to add another layer (View Model) in order to take out dependencies // public ViewModel { private prop IPersonRepository and other properties // use ViewModel to bind all data to UI controls => then in UI page declare ViewModel // EX: viewModel = new ViewModel() => view model has all the data and access and fetching from DB // now we can do Unit Tests => just on ViewModel (responsible for all the work) // Layered approach // 1. Application => UI, click buttons etc // 2. ViewModel => does all the fetching from db/service/csv // 3. Repository => actual repos (CSV/SQL etc) => GetPerson, Update, Insert // 4. DataStorage => actual DB or CSV file // LAYERED APPROACH // 1. APPLICATION => Program/UI => has/init new ViewModel() // 2. VIEWMODEL => defines IPersonRepository() and has all CRUD Methods needed for UI // 3. REPOSITORY => using { } => Concrete type => gets the data from DB/CSV etc // 4. DATA_STORAGE => actual file or SQL DB // This would be in UI constructor class //MainViewModel viewModel; //viewModel = new MainViewModel(); //viewModel.FetchDataForUi(); // UNIT TESTING // Test if people box gets populated // Its easy now since we can use FakeRepository (consistant data), and test MainViewModel // to see if it gets populated correctly // TO GET FULLY QUALIFIED NAME //var fakeRepo = new FakeRepository(); //string fullyQualifiedName = fakeRepo.GetType().AssemblyQualifiedName; }
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. } } } } }