Results 1 to 3 of 3
  1. #1
    Choochilla is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default Need Help On Project!

    cqObj.fName();
    cqObj.FirstName = userInput.next();

    if(cqObj.FirstName.isEmpty()){
    System.out.print("Please enter a first name that isn't blank: ");
    cqObj.FirstName = userInput.next();
    }

    cqObj.lName();
    cqObj.LastName = userInput.next();

    if(cqObj.LastName.isEmpty()){
    System.out.print("Please enter a last name that isn't blank: ");
    cqObj.LastName = userInput.next();
    }

    I'm trying to make sure that when a user runs the program and enters there first and last names that they do not enter a blank value. My problem is, is that when i run the program and press enter to enter a blank value the program just goes down a line and no error message is issused (the please enter a name that isnt blank). It wont record the name until you enter a name with letters in it but it will not display the message. So it is half working....

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Need Help On Project!

    Instead of using an if/else you need to put each Ask question/Get response in a while loop that does not exit until the user has entered correct data or asked to exit the program.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Nhatmeister is offline Member
    Join Date
    Aug 2013
    Posts
    11
    Rep Power
    0

    Default Re: Need Help On Project!

    I believe hitting Enter doesn't mean obj.next() will get an empty string. I think it's still waiting for you to enter the data...Can't remember where I read this !!! you might want to check the String API (String.next())

Similar Threads

  1. Replies: 7
    Last Post: 11-27-2012, 11:16 AM
  2. Replies: 1
    Last Post: 05-17-2012, 10:43 PM
  3. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 10:14 AM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 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
  •