#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    I/O and String Tokenizer Problem


    Outline I have created for the Problem:

    Open file “person.db” and load the file content into an array of objects (either student or faculty). Each line represents the data needed for each object, and there will be at most 100 lines in the file. Here are the formats of the file content.

    For each faculty:
    ID; First name; Last name; Street address; city, state, zip code; phone; email; office location; day hired; rank; expertise; salary amount

    For each student:
    ID; First name; Last name; Street address; city, state, zip code; phone; email; day accepted; seniority; major; advisor’s name; list of taken classes separated by a comma; list of taking classes separated by comma

    2. After the file is load successfully, the user will be presented with the following menu:
    a. Add a person
    b. Search for a person
    c. Exit
    + The “Add a person” option allows the user to either add a new student or a new faculty
    +The “Search for a person” allows the user to search for
     Any person with given last name and first name or by a given ID
     Students with given last name and first name
     Faculty with given last name and first name
    + The “Exit” option will terminate the program


    I'm reading the file in using the Scanner class. How do I chop up the contents using the String tokenizer class. I know I have to use the semicolon as a delimiter. Also how do I pass the contents to an object array?

    Here is my code so far:

    public class Person {

    String [] Student = new String[5];
    String [] Faculty = new String [5];

    private Scanner x;// Reads the file



    public void OpenFile(){
    try {

    x = new Scanner(new File("person.db"));

    }
    catch(Exception e){

    System.out.println("File not found");
    }
    }


    }


    I am new to java could someone point me in the right direction. Thank you for your time.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    How do I chop up the contents using the String tokenizer class
    What have you tried?
    Basically you use the class's constructor to define what is to be tokenized.
    Have you read the API doc for the class?
    http://docs.oracle.com/javase/7/docs/api/

IMN logo majestic logo threadwatch logo seochat tools logo