/** Pesodo of main. * * boolean userSelectsExitFlag = false; * do * do * * boolean ShapeTypeErrorcheck flag = false; * string shapeInput = ""; * * * Prompts input menu * shapeInput = waits for user to select shape type * ShapeTypeErrorcheck = CheckShapeTypeInput(shapeInput); * if ShapeTypeErrorcheck is false * display message which says input is wrong and what is acceptable input. * * until ShapeTypeErrorCheckFlag is true. * if (shapeInput != 0) * Char selectedShape = shapeIput; * Switch case (selectedShape) * case A * InputMangementShapeRectangle * break; * case B * InputMangementShapeSquare * break; * case C * InputMangementShapeBox * break; * case D * InputMangementShapeCube * break; * case E * InputMangementShapeEllipse * break; * case F * InputMangementShapeCircle * break; * case G * InputMangementShapeCylinder * break; * case H * InputMangementShapeSphere * break; * case I * InputMangementShapeTriangle * break; * case J * InputMangementShapeTetrahedron * break; * default : * Prompt InputMangement * break; * End SelectCase * Else * userselectsexitFlag = true; * until user selects exit. * display Chart from created shapes. */ static void Main(string[] args) { Shape[] shapeArr = new Shape[100]; int numOfShapesMade = 0; //integer numOfShapesMade will keep count of the number of shapes that get created. Boolean userSelectsExitFlag = false; //boolean userSelectExitFlag will control first loop which keep ends when user chooses zero. do //First loop. do while the user hasnt entered '0' to exit { Boolean ShapeTypeErrorCheckflag = false; //boolean ShapeTypeErrorCheckflag will control second loop which ends when user enters a correct value. This allows for repromt of main menu when user enters inncorect value. char shapeInput = ' '; //Character shapeInput will hold the returned character from promptsinputmenu method. do { ShapeTypeErrorCheckflag = false; shapeInput = Promptsinputmenu(numOfShapesMade); //Call method promptsinputmenu(numOfShapesMade). Displays main menu and returns the user input. Integer numOfShapesMade is passed as a parameter to be displayed in the menu as the number of shapes that have been created. shapeInput = Char.ToUpper(shapeInput); //Change Character too a upper case character. ShapeTypeErrorCheckflag = CheckShapeTypeInput(shapeInput); //Call method CheckShapeTypeInput(shapeInput). This checks the variable shapeinput and returnets false if shapeinput was not an allowed character. Returns true if it was a allowed character. //if shapeTypeErroCheckflag is false then display error message. if (ShapeTypeErrorCheckflag == false) { //display message which says input is wrong and what is acceptable input. Console.WriteLine(""); Console.WriteLine("The input was:" + shapeInput); Console.WriteLine("Input was not accepted. Please enter a leter that is listed in the menu or 0 to show all objects that have been created."); } } while (ShapeTypeErrorCheckflag == false); //End of Second do while loop. if var ShapeTypeErrorCheckflag was set to true the loop will end. This means the input entered was an acceptable input for the menu. //If shapeInput is not '0' then it must be a letter of a menu choice of a shape. Else it is '0' and the user chose to display all the shapes. if (shapeInput != '0') { // This switch manages the choice of shape. switch (shapeInput) { case 'A': // A was entered into input, meaning Rectangle was chosen Rectangle rectangle = new Rectangle(); shapeArr[numOfShapesMade] = rectangle; break; case 'B': // B was entered into input, meaning Square was chosen Square square = new Square(); //add square to shape array shapeArr[numOfShapesMade] = square; break; case 'C': // C was entered into input, meaning Box was chosen Box box = new Box(); shapeArr[numOfShapesMade] = box; break; case 'D': // D was entered into input, meaning Cube was chosen Cube cube = new Cube(); shapeArr[numOfShapesMade] = cube; break; case 'E': // E was entered into input, meaning Ellipse was chosen Ellipse ellipse = new Ellipse(); shapeArr[numOfShapesMade] = ellipse; break; case 'F': // F was entered into input, meaning Circle was chosen Circle circle = new Circle(); shapeArr[numOfShapesMade] = circle; break; case 'G': // G was entered into input, meaning Cylinder was chosen Cylinder cylinder = new Cylinder(); shapeArr[numOfShapesMade] = cylinder; break; case 'H': // H was entered into input, meaning Sphere was chosen Sphere sphere = new Sphere(); shapeArr[numOfShapesMade] = sphere; break; case 'I': // I was entered into input, meaning Triangle was chosen Triangle triangle = new Triangle(); shapeArr[numOfShapesMade] = triangle; break; case 'J': // J was entered into input, meaning Tetrahedron was chosen Tetrahedron tretrahedron = new Tetrahedron(); shapeArr[numOfShapesMade] = tretrahedron; break; default: // Default shouldnt occur. Displays error message if it ever does, and switch flags to false so loop continues. Console.WriteLine("Error: default switch option got selected. This shouldnt be possible"); userSelectsExitFlag = false; ShapeTypeErrorCheckflag = false; break; }// End SelectCase numOfShapesMade++; // A shape has now been made. Increment numOfShapesMade by 1. } else //else for if shapeinput != 0 { userSelectsExitFlag = true; // change userSelectsExitFlag to true because user entered 0 requesting shapes to be displayed. }// End if shapeinput != 0 }while (userSelectsExitFlag == false); // End of first loop. If user entered 0 then the userSelectsExitFlag would have been switched. displayChartFromCreatedShapes(shapeArr, numOfShapesMade); //call method displayChartFromCreatedShapes. This displays all the choosen shapes. }
private static int option; // user's choice of the shape at a particular instinct /// <summary> /// The main method of the project /// </summary> /// <param name="args"></param> static void Main(string[] args) { List <Shape> shapes = new List <Shape>();// array list of the shapes and all their instances Console.WriteLine("----------------------S H A P E S----------------------"); bool isRunning = true; //loop control variable while (isRunning) { Console.WriteLine("Select your shape:\n" + "1 - Square\n" + "2 - Rectangle\n" + "3 - Circle\n" + "4 - Triangle\n" + "5 - Ellipse\n" + "6 - Sphere\n" + "7 - Box\n" + "8 - Cube\n" + "9 - Cylinder\n" + "10 - Tetrahedron\n" + "0 - Exit\n"); Console.WriteLine($"You have {Shape.Count} shape(s) as of this instance"); Console.WriteLine("Type '11' to see all your shapes\n"); option = int.Parse(Console.ReadLine()); bool x = true; try { switch (option) // iterating through the choices that user picks { case 0: isRunning = false; break; case 1: while (x) //to prompt the command until the user enters a valid value { Console.WriteLine("Please enter the side of your square"); double side = double.Parse(Console.ReadLine()); // reads what the user typed if (side > 0) { Shape square = new Square("2D Shape - Square", side); // new instance of the Shape Square shapes.Add(square); // square is added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 2: while (x) { Console.WriteLine("Please enter the length of your rectangle"); double length = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the width of your rectangle"); double width = double.Parse(Console.ReadLine()); if (length > 0 && width > 0) { Shape rectangle = new Rectangle("2D Shape - Rectangle", length, width); // instance of Shape Rectangle shapes.Add(rectangle); //rectangle added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 3: while (x) { Console.WriteLine("Please enter the radius of your circle"); double radius = double.Parse(Console.ReadLine()); if (radius > 0) { Shape circle = new Circle(radius, "2D Shape - Circle"); //instance of the Shape Circle shapes.Add(circle); //circle added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 4: while (x) { Console.WriteLine("Please enter the edge of your triangle"); double edge = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the height of your triangle"); double height = double.Parse(Console.ReadLine()); if (edge > 0 && height > 0) { Shape triangle = new Triangle("2D Shape - Triangle", edge, height); //instance of the Shape Triangle shapes.Add(triangle); // triangle added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 5: while (x) { Console.WriteLine("Please enter the first axis of your ellipse"); double r1 = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the second axis of your ellipse"); double r2 = double.Parse(Console.ReadLine()); if (r1 == r2 && r2 != 0) { Shape circle = new Circle(r1, "2D Shape - Circle"); Console.WriteLine("Since both the axes are equal, therefore, it " + "is basically a circle"); shapes.Add(circle); x = false; } if (r1 > 0 && r2 > 0) { Shape ellipse = new Ellipse("2D Shape - Ellipse", r1, r2); //instance of the Shape Ellipse shapes.Add(ellipse); // ellipse added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 6: while (x) { Console.WriteLine("Please enter the radius of your sphere"); double radius = double.Parse(Console.ReadLine()); if (radius > 0) { Shape sphere = new Sphere("3D Shape - Sphere", radius); //instance of the Shape Sphere shapes.Add(sphere); //sphere added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 7: while (x) { Console.WriteLine("Please enter the length of your box"); double length = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the width of your box"); double width = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the height of your box"); double height = double.Parse(Console.ReadLine()); if (length > 0 && width > 0 && height > 0) { Shape box = new Box("3D Shape - Box", length, width, height); //instance of the Shape Box shapes.Add(box); //box added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 8: while (x) { Console.WriteLine("Please enter the side of your cube"); double side = double.Parse(Console.ReadLine()); if (side > 0) { Shape cube = new Cube("3D Shape - Cube", side); //instance of the Shape Cube shapes.Add(cube); // cube added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 9: while (x) { Console.WriteLine("Please enter the radius of your cylinder"); double radius = double.Parse(Console.ReadLine()); Console.WriteLine("Please enter the height of your cylinder"); double height = double.Parse(Console.ReadLine()); if (radius > 0 && height > 0) { Shape cylinder = new Cylinder("3D Shape - Cylinder", radius, height); //instance of the Shape Cylinder shapes.Add(cylinder); // cylinder added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 10: while (x) { Console.WriteLine("Please enter the edge of your tetrahedron"); double edge = double.Parse(Console.ReadLine()); if (edge > 0) { Shape tetrahedron = new Tetrahedron("3D Shape - Tetrahedron", edge, edge); //instance of the Shape Tetrahedron shapes.Add(tetrahedron); //tetrahedron added to the array list x = false; } else { Console.WriteLine("Invalid entry\n"); } } break; case 11: Console.WriteLine("\nShape\t\tType\t\tDimensions\t\tArea\t\tVolume"); foreach (Shape s in shapes) //iterating through the array list and displaying all { Console.WriteLine(s); } break; default: Console.WriteLine("Invalid! Please try again"); break; } } catch (Exception ex) { Console.WriteLine("Invalid Entry! " + ex.Message + " Please try again.\n"); } } }
/// <summary> /// ShapeChoice: Checks what shapes user choose /// </summary> private static void ShapeChoice() { int shapesCounter = Shape.GetCount(); // bool result = true; // bool wrongInput = false; // switch (userInput.ToUpper()) { case "A": shape[shapesCounter] = new Rectangle(); break; case "B": shape[shapesCounter] = new Square(); break; case "C": shape[shapesCounter] = new Box(); break; case "D": shape[shapesCounter] = new Cube(); break; case "E": shape[shapesCounter] = new Ellipse(); break; case "F": shape[shapesCounter] = new Circle(); break; case "G": shape[shapesCounter] = new Cylinder(); break; case "H": shape[shapesCounter] = new Sphere(); break; case "I": shape[shapesCounter] = new Triangle(); break; case "J": shape[shapesCounter] = new Tetrahedron(); break; case "0": result = false; break; default: WrongChoice(); wrongInput = true; break; } if (result && !wrongInput) { shape[shapesCounter].SetData(); } usertInputResult = result; }