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

    Default Need help with program

    I am new to enumerated data types and basically I have to read in a file and convert strings to enums. I need help on finding out why this wont run properly I have already made the enumerated classes which are:
    Java Code:
    public enum PassengerType { FIRSTCLASS, ECONOMIC }
    public enum CrewType { PILOT, FLIGHTATTENDANCE }
    public enum AirlineCode { AA, DL, UA, US, NW, SW }
    
    
    public class HUairport2_Macklin	
    {	
    	public static void main(String[] args) throws IOException
    	{
    		PassengerType pType;
    		CrewType cType;
    		AirlineCode aCode;
    		String line;
    		String name;
    		String seat;
    		String letter;
    		
    		System.out.println("The following list consits of the passengers flying from the airport.");
          System.out.println("---------------------------------------------------------------------");   	
          System.out.println("### Flight AA ###");
    		
    		File file = new File("PassengerList.txt");
    		Scanner inputFile = new Scanner(file);
    		
    		ArrayList AA = new ArrayList(); 
    		ArrayList DL = new ArrayList();
    		ArrayList UA = new ArrayList();
    		ArrayList SW = new ArrayList();
    		ArrayList NW = new ArrayList();
    		ArrayList US = new ArrayList();
    		
    		while(inputFile.hasNext())
    		{
    			line = inputFile.nextLine();
    			
    			StringTokenizer strTokenizer = new StringTokenizer(line);
    			
    				letter = strTokenizer.nextToken();
    				name = strTokenizer.nextToken();
    				aCode = AirlineCode.valueOf(strTokenizer.nextToken());
    				seat = strTokenizer.nextToken();
    			
    			if(letter.equals("F") || letter.equals("E"))
    			{
    				pType = PassengerType.valueOf(letter);
    				Passenger aPeople = new Passenger(pType, name, aCode, seat);
    				
    				
    				if(pType.equals("F"))
    				{
    					pType = PassengerType.valueOf("First Class");
    				}
    				else if(pType.equals("E"))
    				{
    					pType = PassengerType.valueOf("Economic");
    				}
    				else
    					System.out.println("Error, " + pType + " is not a valid passenger type.");
    				
    				if(aCode.equals("AA"))
    					AA.add(aPeople);
    				else if(aCode.equals("DL"))
    					DL.add(aPeople);
    				else if(aCode.equals("UA"))
    					UA.add(aPeople);
    				else if(aCode.equals("SW"))
    					SW.add(aPeople);
    				else if(aCode.equals("NW"))
    					NW.add(aPeople);
    				else if(aCode.equals("US"))
    					US.add(aPeople);
    				else
    					System.out.println("Error, " + aCode + " is an invalid airport.");
    			}
    			
    			if(letter.equals("P") || letter.equals("A"))
    			{
    				cType = CrewType.valueOf(letter);
    				
    				Crew bPeople = new Crew(name, cType, aCode);
    				
    				if(cType.equals("P"))
    				{
    					CrewType.valueOf("Pilot"); 
    				}
    				else if(cType.equals("A"))
    				{
    					CrewType.valueOf("Flight Attendance");
    				}
    				else
    					System.out.println("Error, " + cType + " is not a valid passenger type.");
    					
    				
    				
    				if(aCode.equals("AA"))
    					AA.add(bPeople);
    				else if(aCode.equals("DL"))
    					DL.add(bPeople);
    				else if(aCode.equals("UA"))
    					UA.add(bPeople);
    				else if(aCode.equals("SW"))
    					SW.add(bPeople);
    				else if(aCode.equals("NW"))
    					NW.add(bPeople);
    				else if(aCode.equals("US"))
    					US.add(bPeople);
    				else
    					System.out.println("Error, " + aCode + " is an invalid airport.");
    			}
    		}
    		inputFile.close();
    		
    				for(int index1 = 0; index1 < AA.size(); index1++)
                   System.out.println("\t" + AA.get(index1));
                for(int index2 = 0; index2 < DL.size(); index2++)
                   System.out.println("\t" + DL.get(index2));
                for(int index3 = 0; index3 < UA.size(); index3++)
                   System.out.println("\t" + UA.get(index3));
                for(int index4 = 0; index4 < SW.size(); index4++)
                   System.out.println("\t" + SW.get(index4));
                for(int index5 = 0; index5 < NW.size(); index5++)
                   System.out.println("\t" + NW.get(index5));
                for(int index6 = 0; index6 < US.size(); index6++)
                   System.out.println("\t" + US.get(index6));
    		
    			
    	}
    }
    Last edited by sunde887; 10-05-2011 at 02:02 AM. Reason: Added code tags, [code]...[/code]

  2. #2
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Need help with program

    What errors are you getting?
    Post them.

  3. #3
    kzaman's Avatar
    kzaman is offline Member
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    4
    Rep Power
    0

    Default Re: Need help with program

    pType = PassengerType.valueOf(letter);

    will not get any value for enum.

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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
  •