Results 1 to 3 of 3
Thread: Need help with program
- 10-05-2011, 02:58 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
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 03:02 AM. Reason: Added code tags, [code]...[/code]
- 10-05-2011, 04:35 AM #2
Senior Member
- Join Date
- Jul 2011
- Location
- Melbourne, Victoria, Australia
- Posts
- 155
- Rep Power
- 10
Re: Need help with program
What errors are you getting?
Post them.
- 10-05-2011, 06:31 AM #3
Similar Threads
-
How to code a program to send messages to a chat program?
By josh2992 in forum New To JavaReplies: 2Last Post: 04-02-2011, 01:57 PM -
How would I open a program from a single button of another program. Help...
By decgaid06 in forum New To JavaReplies: 13Last Post: 03-22-2011, 07:49 AM -
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 07:53 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 03:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 10:33 PM
Bookmarks