Results 1 to 15 of 15
  1. #1
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default Problem with menu-driven program

    I have a program that I have to write and can not figure out why the way I'm writing the menu isn't working. Here is my block of code for the menu so far, you can see I'm only working with 1 input so far, and I am getting an error compiling in ** ProcessPicture(input);** this line. Any help would be greatly appreciated.

    public static void main(String[] args)
    {
    Scanner in = new Scanner (System.in);
    int userChoice;
    boolean quit = false;
    //Picture q = p.oilPaint(5);
    //q.explore();
    do {
    System.out.println("1. Choose a Picture to Process");
    System.out.println("2. Display Picture");
    System.out.println("3. Make Picture Black & White");
    System.out.println("4. Make Picture Negative color");
    System.out.println("5. Flip Picture 180 Degrees");
    System.out.println("6. Save Picture to New File");
    System.out.print("Pick a choice above or press 0 to Quit: ");
    userChoice = in.nextInt();
    switch (userChoice) {
    case 1:
    // process picture
    ProcessPicture(input);
    break;
    case 2:
    // display picture
    break;
    case 3:
    // black and white
    break;
    case 4:
    // negative
    break;
    case 5:
    // flip 180 degrees
    break;
    case 6:
    // save to new file
    break;
    case 0:
    quit = true;
    break;
    default:
    System.out.println("Invalid Selection, please select a choice above.");
    break;
    }
    System.out.println();
    }
    while (!quit);
    System.out.println("Have a nice day");
    }
    private void ProcessPicture(java.io.InputStream input){
    Scanner in = new Scanner(input);
    Picture p =
    new Picture(FileChooser.pickAFile());
    p.explore();
    }
    /*private void DisplayPicture(java.io.InputStream input)
    private void BlackAndWhite(java.io.InputStream input)
    private void Negative(java.io.InputStream input)
    private void FlipUpsideDown(java.io.InputStream input)
    private void Save(java.io.InputStream input)
    */

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    I am getting an error compiling
    please copy and paste the full text of the error message here.

  3. #3
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    if i put....

    Scanner in = new Scanner(input);
    Picture p =
    new Picture(FileChooser.pickAFile());
    p.explore();

    into my case 1:, then it works fine. I could do this to complete the assignment but i'd rather learn how to do it correctly.

  4. #4
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    the error says...

    File: C:\------------\PictureMenu.java [line: 460]
    Error: C:\------------\PictureMenu.java:460: cannot find symbol
    symbol : variable input
    location: class PictureMenu

    oh and I am using DrJava if that matters

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    please copy and paste the full text of the error message here.

    Your edited version leaves stuff off.

    Where is the variable input defined? Is it in scope where you are trying to use it?

  6. #6
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    It isn't, the last time I did a program similar to this, I had Scanner in = new Scanner (input); and it worked fine. However when I put that in, it also creates an error.

    I think I'm missing something really basic, but I can't figure out what I'm doing wrong.
    Last edited by t0nydanzuh; 09-30-2010 at 06:32 PM.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    please copy and paste the full text of the error message here.

  8. #8
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    If you use code tags, your indentations will be perserved.

    I have never used case/switch statments before, except
    long ago in a Pascal assignment.

    All of your clues indicate to me that blocks of code within
    a switch-case statement that have more than one line
    of code (beyond a solitary "break;" statement), need to
    have braces {} enclosing them.

    Also, it is optional, but some consider it good practice to
    place single lines of code, such as all of your "break;"
    statements in braces {}.

    EMENDED!! I'VE JUST REVEWED MANY JAVA CASE
    EXAMPLES, AND I SEE I REALLY DON'T HAVE
    GOOD EXPERIENCE WITH THIS TOPIC.

    However, I have found an error in my indentation
    of my interpretation of this code, and have corrected
    it below.


    Java Code:
      public static void main(String[] args){
        Scanner in = new Scanner (System.in);
        int userChoice;
        boolean quit = false;
        //Picture q = p.oilPaint(5);
        //q.explore();
        do {
          System.out.println("1. Choose a Picture to Process");
          System.out.println("2. Display Picture");
          System.out.println("3. Make Picture Black & White");
          System.out.println("4. Make Picture Negative color");
          System.out.println("5. Flip Picture 180 Degrees");
          System.out.println("6. Save Picture to New File");
          System.out.print("Pick a choice above or press 0 to Quit: ");
          userChoice = in.nextInt();
          switch (userChoice) {
            case 1:
              // process picture
              ProcessPicture(input);    // Probably all of this should
              break;                         // be enclosed in braces {}
            case 2:
              // display picture
              break;
            case 3:
              // black and white
              break;
            case 4:
              // negative
              break;
            case 5:
              // flip 180 degrees
              break;
            case 6:
              // save to new file
              break;
            case 0:
              quit = true;
              break;
            default:
              System.out.println("Invalid Selection, please select a choice above.");
              break;
          }
          System.out.println();
        }
        while (!quit);
        System.out.println("Have a nice day");
      }
    
      private void ProcessPicture(java.io.InputStream input){
        Scanner in = new Scanner(input);
        Picture p = new Picture(FileChooser.pickAFile());
        p.explore();
      }
    
      /*private void DisplayPicture(java.io.InputStream input)
      private void BlackAndWhite(java.io.InputStream input)
      private void Negative(java.io.InputStream input)
      private void FlipUpsideDown(java.io.InputStream input)
      private void Save(java.io.InputStream input)
      */ 
    }
    Last edited by paul pasciak; 09-30-2010 at 09:58 PM. Reason: Indentation and not experienced with this topic

  9. #9
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    1 error found:
    File: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java [line: 461]
    Error: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java:461: cannot find symbol
    symbol : variable input
    location: class PictureMenu

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    What is the source code on line 461?
    Did you leave off some of the error message? When I compile with an error I get:
    Java Code:
    TestCode2.java:45: cannot find symbol
    symbol: variable TRUE
             return TRUE;
                    ^
    1 error
    Notice the source line and the ^ pointer.

  11. #11
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    line 461 is:

    ProcessPicture(input);

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default

    Where is the variable: input defined?
    I think I already have asked this question in post#5.

  13. #13
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    i figured it out. What happened is I had this in the main method, and it couldnt work that way. Here's my working code, thanks for the help.


    Scanner in = new Scanner (System.in);
    public static void main(String[] args)
    {
    PictureMenu p = new PictureMenu();

    p.PictureMenus(System.in);
    }
    public void PictureMenus(java.io.InputStream input){
    Scanner in = new Scanner (input);
    int userChoice;
    boolean quit = false;
    //Picture q = p.oilPaint(5);
    //q.explore();
    do {
    System.out.println("1. Choose a Picture to Process");
    System.out.println("2. Display Picture");
    System.out.println("3. Make Picture Black & White");
    System.out.println("4. Make Picture Negative color");
    System.out.println("5. Flip Picture 180 Degrees");
    System.out.println("6. Save Picture to New File");
    System.out.print("Pick a choice above or press 0 to Quit: ");
    userChoice = in.nextInt();
    switch (userChoice) {
    case 1:
    // process picture
    ProcessPicture(input);
    break;
    case 2:
    // display picture
    break;
    case 3:
    // black and white
    break;
    case 4:
    // negative
    break;
    case 5:
    // flip 180 degrees
    break;
    case 6:
    // save to new file
    break;
    case 0:
    quit = true;
    break;
    default:
    System.out.println("Invalid Selection, please select a choice above.");
    break;
    }

    System.out.println();
    }
    while (!quit);
    System.out.println("Have a nice day");
    }
    private void ProcessPicture(java.io.InputStream input){
    Scanner in = new Scanner(input);
    Picture p =
    new Picture(FileChooser.pickAFile());
    p.explore();
    }
    /*private void DisplayPicture(java.io.InputStream input)
    private void BlackAndWhite(java.io.InputStream input)
    private void Negative(java.io.InputStream input)
    private void FlipUpsideDown(java.io.InputStream input)
    private void Save(java.io.InputStream input)
    */
    }

  14. #14
    t0nydanzuh is offline Member
    Join Date
    Sep 2010
    Posts
    12
    Rep Power
    0

    Default

    Since I have your attention, do you know the best way to save a picture to a new file? with extensions such as .jpg or .gif

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

Similar Threads

  1. Menu-driven console help please
    By floppyspace in forum New To Java
    Replies: 4
    Last Post: 03-12-2010, 04:12 PM
  2. how to create menu-driven programs?
    By princess.blue in forum Eclipse
    Replies: 0
    Last Post: 12-07-2009, 08:01 AM
  3. need menu program
    By student_doesntget_java in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 09:58 AM
  4. Menu driven system - atm
    By thelinuxguy in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2009, 11:14 PM
  5. Replies: 1
    Last Post: 07-13-2008, 03:16 PM

Posting Permissions

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