I am working on a java project,i want to sequentially read an ASCII file into an arraylist and then add a method to print out the array. i want to also be able to search through the ASCII file

can anyone help me with the coding. will realy b much appreciated

I am very new to java, but this is what i have , basically this code reads the file. but i dont know how to make it ask the user to print the ascii code. and i need to ask the user to input a text for the programm to search the file and output to the user weather the word or line is in the text file. full detail about wat am doing is is below after the code.

import java.util.*;
import java.io.*;
/**
 * Write a description of class ArrayAirlineTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ArrayAirlineTester
{
   static BufferedReader fileInput;
   public static void main (String args[] ) throws IOException
   {  
       Scanner keyboard = new Scanner (System.in);
       String flightNumber;
       String inputString;
       String fileName;
       String destination;
       int numberOfAirline = 20;
       System.out.print  ( "   " );
       
       StringTokenizer tokens;
       Scanner console = new Scanner (System.in);
       ArrayAirline a = new ArrayAirline ( numberOfAirline);
       try
       {
           System.out.print ( "File name ?  ");
           fileName = console.nextLine();
           fileInput = new BufferedReader( new FileReader(fileName)); // students.dat
           inputString = fileInput.readLine();
           while(inputString != null)
       {
//First you need to split the string using the String Tokenizer
     tokens = new StringTokenizer(inputString);
     //Extract the first field - Flight number
flightNumber = tokens.nextToken();
//Extract the second field - destination
destination = tokens.nextToken();
//Create object and insert into array
a.insertAirline(new Airline(flightNumber, destination));
inputString = fileInput.readLine();
           } //end of while
//print array
a.printArray();
}
catch(FileNotFoundException e)// if file is not found
   {
System.out.println("File not found " + e.toString());
}
} //end of main
}// end of class ArrayAirline

Use appropriate classes and methods to implement a Java program that reads the ASCII file (see below) sequentially into an array of Airline objects. Airline objects consist of two fields, flight number and destination. Implement the following functionalities:

THE ASCII FILE:
AM321 Malta
EA221 Alexandria
BA120 Cairo
SA560 Johannesburg
NA123 Lagos
KA232 Nairobi
MA441 Casablanca
CA127 Montreal
AA103 Washington
UA156 Boston
RA123 Moscow
AA332 Atlanta
CA145 Havana
JA211 Kingston
AF562 Paris
AE231 Calcutta
AE210 Karachi
AE114 Madras
JL313 Tokyo
LH412 Berlin


THANKS SO MUCH FOR YOUR HELP
1. Add a method that prints the array. [provide output]
2. Add a method that searches for a flight number and returns a reference to the object. Use the reference returned by the method to display the object’s data (i.e. flight details). If the flight is not found then the method should return null and the ‘caller’ should display an appropriate message, e.g. “flight not found”. [provide output]

Edited 6 Years Ago by masijade: added code tags

This article has been dead for over six months. Start a new discussion instead.