Results 1 to 11 of 11
  1. #1
    dillmann74 is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default How do I create a simple stop commmand in an elementary Java program?

    I need to create a simple "stop" command in an elementary Java program.
    Here is where I need it.......

    System.out.print( "Enter employee name:" );
    String nameOfEmployee = input.next();
    System.out.println();

    Here is what I attempted and failed......

    if ( nameOfEmployee.equalsIgnoreCase ( ";stop"; )) {
    break;
    }

    I will be honest with you all.... I AM a student, I am not looking for someone to do the assignment for me. However the assigned readings get me absloutley no where as I have just been introduced to this language. I want to do my own work for this class. But, I am just boggled. Moral is really low...... Someone please HELP!!!! Thank you in advance!!!!

  2. #2
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Quote Originally Posted by dillmann74 View Post
    if ( nameOfEmployee.equalsIgnoreCase ( ";stop"; )) {
    break;
    }
    why you have this ";stop"; ?
    instead it should be,
    Java Code:
    if ( nameOfEmployee.equalsIgnoreCase ( "stop" )) {
    break;
    }
    and for 'break;' syntax it will just get out of current if loop.

    -Regards;)

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default

    What do you want the program to do when "stop" (or ";stop;") is encountered?

    If it's exit then you can use System.exit(), but try and make sure that's only done at the top of the code, in case you leave resources open. This probably won't apply in your case, but it's good practice not to call System.exit() willy nilly.

  4. #4
    dillmann74 is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    I would like the command prompt window to terminate or just completely go away. There will also be some modification to the program. As of right now, the program is throwing one error and that is in the break command that I just put in.

    if ( nameOfEmployee.equalsIgnoreCase ( "stop" )){
    break;
    }

    I also need to manipulate this program to calculate and track overtime hours.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,305
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by dillmann74 View Post
    I would like the command prompt window to terminate or just completely go away. There will also be some modification to the program. As of right now, the program is throwing one error and that is in the break command that I just put in.

    if ( nameOfEmployee.equalsIgnoreCase ( "stop" )){
    break;
    }

    I also need to manipulate this program to calculate and track overtime hours.
    You can only use the 'break' statement in the body of a loop or in a case clause; it is a plain syntax error (a compiler error) to use it anywhere else.

    kind regards,

    Jos

  6. #6
    shai is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    You are looking for either:

    if (nameOfEmployee.equalsIgnoreCase("stop")) {
    return; // of course assuming the return type of the method is void
    }

    or:

    if (nameOfEmployee.equalsIgnoreCase("stop")) {
    System.exit(-1); // note that -1 doesn't have to be the argument, it can be any number.
    }

    Good luck.
    Last edited by shai; 08-13-2010 at 06:23 PM.

  7. #7
    dillmann74 is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    Hello Shai,
    HOLY COW! it worked!!! Throws no errors! U R AWESOME!!!! This is exiting stuff!!!!!!!!! I will continue to work on this homework and I am sure that I will have more questions as the weekly readings are a joke. THANX SO MUCH!!!!!

  8. #8
    dillmann74 is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default Same program different problem

    Now I am having issues with getting my program to decipher and display over time hours along with regular hours. I am also having troubles getting the program to repeat a question after an invalid number is entered. Once again I am running text pad in windows xp. Are there any suggestions? Thanks so much in advance.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

  10. #10
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    use a do while loop to have the question repeat.
    for the overtime hour thing, well i cant see your code so im just taking a stab in the dark here but im assuming "deciper" is the result of some sort of math equation? if thats the case create an interger variable and make it the result of the math equation and then use println to diplay the integer afterwards
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

Similar Threads

  1. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 12:50 PM
  2. Simple Java program
    By Rolle in forum New To Java
    Replies: 3
    Last Post: 10-26-2009, 04:05 PM
  3. [SOLVED] Need help with simple Java program
    By hungdukie in forum New To Java
    Replies: 5
    Last Post: 11-26-2008, 03:17 AM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:40 AM

Posting Permissions

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