Results 1 to 4 of 4
Thread: [SOLVED] Help with if...else...
- 04-23-2008, 07:07 PM #1
Member
- Join Date
- Apr 2008
- Posts
- 7
- Rep Power
- 0
[SOLVED] Help with if...else...
This program has been driving me nuts. I cannot get a clean compile. The more I look at, the more I just want to completely forget about it. Could someone take a look at it and see if you notice anything wrong?
and the errors:Java Code:import java.io.*; public class ifExample { public static void main (String Args[]) throws IOException { String day; String name = ("Jamie Ambrose"); String monday = ("\n --Monday Schedule-- \n MA103 11:00am - 12:15pm \n PS101 2:00pm - 3:15pm"); String tuesday = ("\n --Tuesday Schedule-- \n CIS106 2:00pm - 3:15pm \n PC103 5:00pm - 7:15pm"); String wenesday = ("\n --Wednesday Schedule--\n MA103 11:00am - 12:15pm \n PS101 2:00pm - 3:15pm"); String thursday = ("\n --Thursday Schedule--\n CIS106 2:00pm - 3:15pm"); String friday = ("\n No class today"); try { BufferedReader bf = BufferedReader (new InputStreamReader(System.in)); System.out.println("Enter the day of week you would like to view: \n Monday-1 \n Tuesday-2 \n Wednesday \n Tursday-3 \n Friday-4"); day = bf.readLine(); int daynum = Integer.parseInt(day); } catch (IOException ioe) { System.out.println("IO exception Occurred"); } if ( daynum == 1) { System.out.println(name + "Todays Scheudle" + 1); } else if ( daynum == 2) { System.out.println(name + "Todays Schedule" + 2); } else if (daynum == 3) { System.out.println(name + "Todays Schedule" + 3); } else if (daynum == 4) { System.out.println(name + "Todays Schedule" + 4); } else if (daynum == 5) { System.out.println(name + "Todays Schedule" + 5); } else { System.out.println("Enter valid number"); } } }
Java Code:G:\Spring 08\CIS 106\ifExample.java:21: cannot find symbol symbol : method BufferedReader(java.io.InputStreamReader) location: class ifExample BufferedReader bf = BufferedReader (new InputStreamReader(System.in)); ^ G:\Spring 08\CIS 106\ifExample.java:33: cannot find symbol symbol : variable daynum location: class ifExample if ( daynum == 1) ^ G:\Spring 08\CIS 106\ifExample.java:38: cannot find symbol symbol : variable daynum location: class ifExample else if ( daynum == 2) ^ G:\Spring 08\CIS 106\ifExample.java:42: cannot find symbol symbol : variable daynum location: class ifExample else if (daynum == 3) ^ G:\Spring 08\CIS 106\ifExample.java:47: cannot find symbol symbol : variable daynum location: class ifExample else if (daynum == 4) ^ G:\Spring 08\CIS 106\ifExample.java:52: cannot find symbol symbol : variable daynum location: class ifExample else if (daynum == 5) ^ 6 errors
- 04-23-2008, 08:19 PM #2
shall beJava Code:BufferedReader bf = BufferedReader (new InputStreamReader(System.in));
The whole code should look like thisJava Code:BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
If you declare the daynum variable inside the try/catch you should use it there.Java Code:import java.io.*; public class ifExample { public static void main(String Args[]) throws IOException { String day; String name = ("Jamie Ambrose"); String monday = ("\n --Monday Schedule-- \n MA103 11:00am - 12:15pm \n PS101 2:00pm - 3:15pm"); String tuesday = ("\n --Tuesday Schedule-- \n CIS106 2:00pm - 3:15pm \n PC103 5:00pm - 7:15pm"); String wenesday = ("\n --Wednesday Schedule--\n MA103 11:00am - 12:15pm \n PS101 2:00pm - 3:15pm"); String thursday = ("\n --Thursday Schedule--\n CIS106 2:00pm - 3:15pm"); String friday = ("\n No class today"); try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out .println("Enter the day of week you would like to view: \n Monday-1 \n Tuesday-2 \n Wednesday \n Tursday-3 \n Friday-4"); day = bf.readLine(); int daynum = Integer.parseInt(day); if (daynum == 1) { System.out.println(name + "Todays Scheudle" + 1); } else if (daynum == 2) { System.out.println(name + "Todays Schedule" + 2); } else if (daynum == 3) { System.out.println(name + "Todays Schedule" + 3); } else if (daynum == 4) { System.out.println(name + "Todays Schedule" + 4); } else if (daynum == 5) { System.out.println(name + "Todays Schedule" + 5); } else { System.out.println("Enter valid number"); } } catch (IOException ioe) { System.out.println("IO exception Occurred"); } } }Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
- 04-23-2008, 10:42 PM #3
Member
- Join Date
- Apr 2008
- Posts
- 7
- Rep Power
- 0
Awesome. Thank you. Now its time to convert it to an applet. Hopefully this goes a lot smoother.
- 04-24-2008, 10:17 AM #4


LinkBack URL
About LinkBacks
Reply With Quote
me! :cool:
Bookmarks