Results 1 to 6 of 6

Thread: Exit System

  1. #1
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default Exit System

    Hi,
    I have a system that contain switch statement, my problem is with the X choice when the user exits the system, how can I write a code that exits the system while printing a message say: Exiting system.
    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    28

  3. #3
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    yes, sorry, that is what I want to do, to print a message and then exit the system

  4. #4
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    here is what I have done:
    Java Code:
    public void select()
    	{	char action = readAction();
    		execute(action);
    		action = readAction();	}
    			
    	private char readAction()
    	{   System.out.print("\tEnter action (A/X): ");
    	    return In.nextLine().toUpperCase().charAt(0);}
    		
    	private void execute(char action)
    	{	switch(action)
    		{case 'A' : add(); break;
                               case 'X' : exit(); break
    		  default: System.out.println("\t\tInvalid action");}}
    private void exit()
    {
    S.o.p("exiting the system");
    
    }
    I don't what else to put in the exit method to exit completely.

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    8

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Do you want the message to be printed and displayed and the system to wait until the user has entered a key to exist the system?

Similar Threads

  1. Avoiding system.exit()
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-01-2009, 10:17 AM
  2. System.exit 0 or 1?
    By antgaudi in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 07:33 PM
  3. System.exit() in catch block.
    By new_2_java in forum Advanced Java
    Replies: 8
    Last Post: 06-24-2008, 03:45 PM
  4. system.exit(..)
    By ramakanta.majhi in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 01:28 AM
  5. help with System.exit (1) function call
    By katie in forum Advanced Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 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
  •