Hi,
I'm just entering my second semester of Java programming so still fairly uncertain about various elements. I have been trying for the past few hours to get this program to compile but it keeps failing. It'd be a great help if one of you fine people could pinpoint the error(s).
I'm using Textpad and its saying theres problems with my switch statement but I think its theres an error when I'm passing variables from the main method to the method containging the switch.
The program is supposed to be a simple text based menu system that allows the user to display various maths tables. It is supposed to gather the required info from the user such as whter they want to view mult or division and how many table lines they would like to display etc. then pass the information to a new method that will display the information to the screen.
Thanks in advance,
Lee.
class assignment2 { public static void main (String[]args) { int table, lines; char type, ans; do{ System.out.println("Please enter the table number you wish to view; "); table = Keyboard.readInt(); while (table > 12 || table < 1 ) { System.out.println("Please enter a number between 1 and 12 inclusive: "); System.out.println("Please enter the table number you wish to view; "); table = Keyboard.readInt(); } System.out.println("Please enter the number of lines you wish to view; "); lines = Keyboard.readInt(); while (lines > 12 || lines < 1) { System.out.println("Please enter a number between 1 and 12 inclusive: "); System.out.println("Please enter the number of lines you wish to view; "); lines = Keyboard.readInt(); } System.out.println("Please choose a table type"); System.out.println("(a) Multiplication (b) Division (c) Modular (d) Quit table"); type = Keyboard.readChar(); while (type != 'a' && type != 'b' && type != 'c' && type != 'd') { System.out.println("Please choose from the selected options"); System.out.println("Please choose a table type"); System.out.println("(a) Multiplication (b) Division (c) Modular (d) Quit table"); type = Keyboard.readChar(); } display (table, lines, type); public static void display (int tablenumber,int numberlines,char tabletype) { int x = 0; int y; switch (tabletype) { case 'a': case 'A': for (x = 1; x <= numberlines; x++) { y = tablenumber * x; System.out.println(tablenumber + " * " + x + " = " + y); }break; case 'b': case 'B': for (x = 1; x <= numberlines; x++) { y = tablenumber / x; System.out.println(tablenumber + " / " + x + " = " + y); }break; case 'c': case 'C': for (x = 1; x <= numberlines; x++) { y = tablenumber / x; System.out.println(tablenumber + " % " + x + " = " + y); }break; case 'd': case 'D': System.out.println("Thank you"); break; } } System.out.println("Would you like to view another table ? 'y' or 'n': "); ans = Keyboard.readChar(); while(ans != 'n' && ans != 'y') { System.out.println("Please choose either 'y' or 'n'"); System.out.println("Would you like to view another table? 'y' or 'n'"); ans = Keyboard.readChar(); } }while (ans == 'y'); } }