/** 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. }
/// <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; }