Results 1 to 2 of 2
  1. #1
    Dex
    Dex is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default Help with prіnt!

    Hey guys I'm just starting to learn java and I'm stuck with a bit of homework.
    I am trying to create some code that starts with a menu, and then when you input "1" it will print out Welcome()
    but I cant get it to print it out, instead it just reprints the menu!
    What am I missing?

    Java Code:
    public class program10 {
      
      public static final int WELCOME = 1;
      public static final int EXIT = 0;
    
      
      public void start(){
        
       int selection = -1;
        boolean userHasFinished = false;
        
        while (! userHasFinished) {
          
          printMenu(); 
          getUserSelection();     
                     
          System.out.println("--------------------------------------------------------");
          System.out.println("--------------------------------------------------------");
          if (selection == WELCOME) {
            printWelcome();
                     
          } else if (selection == EXIT) {
            userHasFinished = true;
          }
          if (!userHasFinished) {
            System.out.println("--------------------------------------------------------");
            System.out.println("--------------------------------------------------------");
            
          }
        }
      }
        private void printMenu() {
       
        System.out.println(EXIT + " - Exit");
        System.out.println(WELCOME + " - Print Welcome");
           }
        
      private void printWelcome() {
       
       System.out.println("Welcome!");
        
         }
     
    
    // method to get user selection
    private int getUserSelection() {
      System.out.print("        Enter selection: ");
      String userSelection = Keyboard.readInput();
      return Integer.parseInt(userSelection);
    }
    
    }
    Last edited by DarrylBurke; 03-19-2012 at 12:38 PM. Reason: Replace 'print' with 'prіnt' in the subject line

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

    Default Re: Help with prіnt!

    You call a method but don't receive the value it returns. You need to save the returned value and use it to control the execution flow.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. how to print this
    By eng.master89 in forum New To Java
    Replies: 1
    Last Post: 01-09-2012, 12:11 AM
  2. Why won't this print?
    By ozzyman in forum Java 2D
    Replies: 0
    Last Post: 05-03-2011, 01:20 AM
  3. Need help with print
    By lala in forum New To Java
    Replies: 0
    Last Post: 11-25-2010, 05:24 PM
  4. cant get to print...
    By chango77745 in forum New To Java
    Replies: 0
    Last Post: 02-13-2009, 06:04 AM
  5. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 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
  •