Results 1 to 3 of 3

Thread: Quick Java Help

  1. #1
    EdOBannon is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Quick Java Help

    For the following code how would I EXIT the program? If the input is equal to 3 I need to exit the program.

    Java Code:
    import java.util.Scanner; // needed to import Scanner class  
    import java.util.ArrayList;
    public class cpb09eTestDrive_A5 {  
        // Create Scanner  
        private static Scanner scan = new Scanner(;  
        //Program Execution  
        public static void main(String[] args) {  
        	ArrayList<cpb09eEmployee_A5> emplist = new ArrayList<cpb09eEmployee_A5>();
            System.out.println("Please indicate the type of employee by typing its number: ");  
            System.out.println("1 - Wage Worker");  
            System.out.println("2 - Executive");  
            System.out.println("3 - Exit");  
            String input = scan.nextLine();  
                //create WageWorker object  
            	cpb09eEmployee_A5 obj = new cpb09eEmployee_A5(); 		// create employee object and initialize it	
            	cpb09eWageWorker_A5 wage = new cpb09eWageWorker_A5();
    			System.out.println("Enter the Objects Name ");
              		String Name =;			// input name from user
              		wage.SetName(Name);					// set the name in employee class
              		System.out.println("Enter the Wage  ");
              		int Wage = scan.nextInt();			// input wage from user
              		wage.SetWage(Wage);   				// set wage of employee	
              		System.out.println("Enter the Hours ");
              		int hours = scan.nextInt();        // input hours from the user
              		wage.SetHours(hours);               //set the hours
              		wage.SetSalary(hours * Wage);			// calculate and set the salary
              	    emplist.add(wage);             		// set the object in array list
            else if(input.equals("2")){  
                //create Executive object  
            	cpb09eEmployee_A5 obj = new cpb09eEmployee_A5();	
            	cpb09eExecutive_A5 exe_obj = new cpb09eExecutive_A5();
            	System.out.println("Enter the Objects Name ");
            		String Name =;				
            	System.out.println("Enter the Salary ");
            		int Sal = scan.nextInt();				
            	System.out.println("Enter the Title ");
            		String title =;        	
            else if(input.equals("3")){  
                //exit the program  
    Last edited by pbrockway2; 11-06-2011 at 10:20 AM. Reason: code tags added

  2. #2
    Cosmos is offline Member
    Join Date
    Jul 2011
    New Delhi,India
    Rep Power

    Default Re: Quick Java Help

    maybe its weird but it is as simple as this-

    just write System.exit(0);

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: Quick Java Help

    Did you see the answers given in your other thread? And understand them?

    That code doesn't need any change in order to exit if the user enters "3". And, please use "code" tags when you post code.

Similar Threads

  1. Quick how-to java applets
    By rperalta in forum Java Applets
    Replies: 1
    Last Post: 09-24-2011, 06:20 PM
  2. Java Quick Start
    By Duchess in forum New To Java
    Replies: 7
    Last Post: 04-26-2009, 11:49 AM
  3. A Java reference source for a quick look
    By tapies in forum New To Java
    Replies: 6
    Last Post: 10-03-2008, 06:01 PM
  4. Quick Java question/help
    By Zedy in forum New To Java
    Replies: 6
    Last Post: 04-22-2008, 03:40 AM
  5. Quick Job required in Java
    By taxman in forum Jobs Offered
    Replies: 0
    Last Post: 01-02-2008, 12:46 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