Results 1 to 4 of 4
  1. #1
    lcrakel87 is offline Member
    Join Date
    Apr 2008
    Posts
    7
    Rep Power
    0

    Default [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?

    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");
    			}
    
    		}
    	}
    and the errors:

    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

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Java Code:
    BufferedReader bf = BufferedReader (new InputStreamReader(System.in));
    shall be

    Java Code:
    BufferedReader bf = new BufferedReader (new InputStreamReader(System.in));
    The whole code should look like this

    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");
            }
        }
    }
    If you declare the daynum variable inside the try/catch you should use it there.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    lcrakel87 is offline Member
    Join Date
    Apr 2008
    Posts
    7
    Rep Power
    0

    Default

    Awesome. Thank you. Now its time to convert it to an applet. Hopefully this goes a lot smoother.

  4. #4
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Hey Icrakel87, If this thread has been answered, please mark it as Solved :)
    Did this post help you? Please me! :cool:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •