but

My problem is that I am trying to get it to tell the user to enter in their input again if they do not enter a number like they are supposed to for case 1 or the square currently it will work if they enter only one letter such as a b or c but not if they enter more than one combined

such as asdf and also it only prints out please try again once after just a single letter is entered than it will break unless they enter a number like they are supposed to

/** * @(#)shape.java * * shape application * * @author * @version 1.00 2008/10/24 */ import java.util.Scanner; public class shape { public static void main(String[] args) { Scanner kboard = new Scanner (System.in); String start, shape, square, triangle, triangle2, rectangle, rectangle2, circle, trapezoid, trapezoid2, trapezoid3, sphere, sphere2, x, x2, y, y2; String[] num = {"1", "2", "3", "4", "5", "6", "7", "8"}; String[] alpha = {"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; boolean go = true; String[] shapes = {"1. SQUARE", "2. TRIANGLE" , "3. RECTANGLE" , "4. CIRCLE" , "5. TRAPEZOID" , "6. SPHERE" , "7. LINE", "8. QUIT"}; System.out.println("WELCOME TO THE SHAPES GAME"); System.out.println("------------------------------"); System.out.println("Created by:\n\n\n"); while (go) { boolean repeat = false; for (int list = 0; list < shapes.length; list++) { System.out.println (shapes[list] + " "); } System.out.println("Please insert the number of the shape you would \nlike to calculate the formulas for: \nENTER 8 TO EXIT!!"); shape = kboard.nextLine(); shape = shape.replaceAll(" ","").toLowerCase(); for (int check = 0; check < num.length; check++) { if (shape.equals(num[check])) repeat = true; } while (!repeat) { System.out.println("Please try again: "); shape = kboard.nextLine(); shape = shape.replaceAll(" ","").toLowerCase(); for (int check = 0; check < num.length; check++) if (shape.equals(num[check])) repeat = true; } int bacon = Integer.parseInt(shape); switch (bacon) { case 1: System.out.println("\n\nYou have entered the square"); System.out.print("Please enter the length of the sides: "); square = kboard.nextLine(); square = square.replaceAll(" ","").toLowerCase(); boolean repeatSQ = false; for (int checkSQ = 0; checkSQ < alpha.length; checkSQ++) { if (square.equals(alpha[checkSQ])) repeatSQ = true; } while (repeatSQ) { System.out.println("Please try again: "); square = kboard.nextLine(); square = square.replaceAll(" ","").toLowerCase(); for (int checkSQ = 0; checkSQ < alpha.length; checkSQ++) if (!square.equals(alpha[checkSQ])) repeatSQ = false; } sqRet(square); break; case 2: System.out.println("\n\nYou have entered the triangle"); System.out.print("Please enter base, height: "); triangle = kboard.nextLine(); triangle = triangle.replaceAll(" ",""); triangle2 = kboard.nextLine(); triangle2 = triangle2.replaceAll(" ",""); triRet (triangle, triangle2); break; case 3: System.out.println("\n\nYou have entered the rectangle"); System.out.print("Please enter length, width: "); rectangle = kboard.nextLine(); rectangle = rectangle.replaceAll(" ",""); rectangle2 = kboard.nextLine(); rectangle2 = rectangle2.replaceAll(" ",""); recRet (rectangle, rectangle2); break; case 4: System.out.println("\n\nYou have entered the circle"); System.out.print("Please enter the radius of the circle: "); circle = kboard.nextLine(); circle = circle.replaceAll(" ",""); cirRet (circle); break; case 5: System.out.println("\n\nYou have entered the trapezoid"); System.out.print("Please enter top base, bottom base, height: "); trapezoid = kboard.nextLine(); trapezoid = trapezoid.replaceAll(" ",""); trapezoid2 = kboard.nextLine(); trapezoid2 = trapezoid2.replaceAll(" ",""); trapezoid3 = kboard.nextLine(); trapezoid3 = trapezoid3.replaceAll(" ",""); traRet (trapezoid, trapezoid2, trapezoid3); break; case 6: System.out.println("\n\nYou have entered the sphere"); System.out.print("Please enter the radius: "); sphere = kboard.nextLine(); sphere = sphere.replaceAll(" ",""); spheRet (sphere); break; case 7: System.out.println("\n\nYou have entered to line"); System.out.print("Please enter first set of points: "); x = kboard.nextLine(); x = x.replaceAll(" ",""); y = kboard.nextLine(); y = y.replaceAll(" ",""); System.out.print("Please enter second set of points: "); x2 = kboard.nextLine(); x2 = x2.replaceAll(" ",""); y2 = kboard.nextLine(); y2 = y2.replaceAll(" ",""); lineRet (x,y,x2,y2); break; case 8: System.out.println("You have chosen to quit"); System.exit(0); go = false; break; default: System.out.println("Please Try Again!!!"); } } } private static void sqRet (String square) { double sq = Double.parseDouble(square); System.out.println("\n\nYou have inserted " + square + " for the sides\n" + "The area of this square is: " + square + "^2" + "=" + (double)Math.pow(sq,2) + "\n\n"); } private static void triRet (String triangle, String triangle2) { double tri = Double.parseDouble(triangle); double tri2 = Double.parseDouble(triangle2); System.out.println("You have inserted a base of " + triangle + " and a height of " + triangle2 + "\nThe area of this triangle is: " + triangle + "^2" + "/2= " + (tri*tri2)/2); } private static void recRet (String rectangle, String rectangle2) { double rec = Double.parseDouble(rectangle); double rec2 = Double.parseDouble(rectangle2); System.out.println("You have inserted a length of " + rectangle + " and a width of " + rectangle2 + "\nThe area of this rectangle is: " + rectangle + "*" + rectangle2 + "= " + (rec*rec2)); } private static void cirRet (String circle) { double circ = Double.parseDouble(circle); System.out.print("You have inserted " + circle + " for the radius\n" + "The area of this circle is: " + circle + "^2" + "*" + "3.14=" + (circ*circ)*3.14 + "\n\n"); } private static void traRet (String trapezoid, String trapezoid2, String trapezoid3) { double trap = Double.parseDouble(trapezoid); double trap2 = Double.parseDouble(trapezoid2); double trap3 = Double.parseDouble(trapezoid3); System.out.println("You have inserted a top base of " + trapezoid + " a bottom base of " + trapezoid2 + " and a height of " + trapezoid3 + "\nThe area of this " + "trapezoid is: 1/2*" + trapezoid3 +"*("+ trapezoid +"+"+ trapezoid2+")" + "=" + (.5*trap3)*(trap+trap2)+"\n\n"); } private static void spheRet (String sphere) { double sph = Double.parseDouble(sphere); System.out.println("\n\nYou have inserted a radius of " + sphere + "\nThe area of this sphere is: " + "4*3.14*" + sphere + "^2" + "=" + (4*3.14*sph*sph) + "\n\n"); } private static void lineRet (String x, String y, String x2, String y2) { double x11 = Double.parseDouble(x); double y11 = Double.parseDouble(y); double x111 = Double.parseDouble(x2); double y111 = Double.parseDouble(y2); double solve = ((x111-x11)*(x111-x11)+(y111-y11)*(y111-y11)); System.out.println("\nYou have inserted the points (" + x + "," + y + ") & (" + x2 + "," + y2 + ")\n" + "The Distance between these points is: " + "The square root of (" + x2 + "-" + x + ")^2+(" + y2 + "-" + y + ")^2=" + Math.sqrt(solve)); } }

really the only code you may need to look at is

String[] alpha = {"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

and

switch (bacon) { case 1: System.out.println("\n\nYou have entered the square"); System.out.print("Please enter the length of the sides: "); square = kboard.nextLine(); square = square.replaceAll(" ","").toLowerCase(); boolean repeatSQ = false; for (int checkSQ = 0; checkSQ < alpha.length; checkSQ++) { if (square.equals(alpha[checkSQ])) repeatSQ = true; } while (repeatSQ) { System.out.println("Please try again: "); square = kboard.nextLine(); square = square.replaceAll(" ","").toLowerCase(); for (int checkSQ = 0; checkSQ < alpha.length; checkSQ++) if (!square.equals(alpha[checkSQ])) repeatSQ = false; } sqRet(square); break;

This post has been edited by **Jayman**: 11 November 2008 - 07:30 PM