ok guys, here is my deal. I'm writing a program for my Comp Programming I class. My assignment says "you are to write a short program that will input a positive integer number in the range 1 - 16. If the input number is not in the correct range a message should be sent to the user until a correct input is submitted. A correct input number is used to print a square which has sides of the input length. The square is made up of an input character." i got that part done. the second part of the lab is "You are to extend the program you wrote in 5A to work for a square, right triangle, or an isosceles triangle. Your program should work regardless of the case input of figure type. You are also to check for incorrect figure type. As in part A above the request for good input is repeated until a valid number or figure type is entered."
I have all of it down, but for some reason the loop i set up to check the validity of the figure shape input wont exit. You enter a valid input, and it just asks you again what figure you would like printed. without the loop the program runs great, as long as you aren't retarded and don't enter an invalid input for the shape of the figure. I get no compile errors from the IDE saying the loop is not set up right....i have no clue whats going on. any ideas?
Scanner keyboard = new Scanner(System.in); int size, p = 1, q = 1; char symbol = 0; String character, character2, shape; final String RIGHT_TRIANGLE = "Right Triangle"; final String ISOSCELES_TRIANGLE = "Isosceles Triangle"; final String SQUARE = "Square"; do { System.out.printf("Enter the size (1 - 16) of the square side: "); size = keyboard.nextInt(); if (size > 16 || size < 1) { System.out.println("Your input was out of range"); } } while (size < 1 || size > 16); System.out.printf("What character is to be used: "); character = keyboard.next(); character2 = character.toUpperCase(); symbol = character2.charAt(0); keyboard.nextLine(); do { System.out.printf("Enter the figure type: Square" + ", Right Triangle, or Isosceles Triangle: "); shape = keyboard.nextLine(); } while (!shape.equalsIgnoreCase(SQUARE) || !shape.equalsIgnoreCase(RIGHT_TRIANGLE) || !shape.equalsIgnoreCase(ISOSCELES_TRIANGLE)); if (shape.equalsIgnoreCase(SQUARE)) { for (int square = 0; square < size; square++) { for (int square2 = 0; square2 < size; square2++) { System.out.print(symbol); } System.out.println(); } } else if (shape.equalsIgnoreCase(ISOSCELES_TRIANGLE)) { for (int yy = 1; yy < size; yy++) { for (int xy = 1; xy < size - yy; xy++) { System.out.print(" "); } for (int z = 1; z <= p; z++) { System.out.print(symbol); } p += 2; System.out.println(""); } } else if (shape.equalsIgnoreCase(RIGHT_TRIANGLE)) { for (int qq = 0; qq < size; qq++) { for (int xq = 0; xq < size - qq; xq++) { System.out.print(" "); } for (int z = 1; z <= q; z++) { System.out.print(symbol); } q += 1; System.out.println(""); } }
any help will be greatly appreciated.