New Assignment. Lost Again!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: New Assignment. Lost Again!!!

  1. #1
    Join Date
    Jul 2004
    Posts
    92

    New Assignment. Lost Again!!!

    yikes. this one is due tonight. it is built upon my other assignment with the banking system, the account, and the client classes. however, now there are more clients and we are to put them into an array.

    ofcourse, i can't find an example NOR has my instructor provided one (actually, we skipped arrays in the lecture for the most part), of an array that is full of objects and filled via the FileReader . . . readLine i think it is.

    i am including our instructions. we are to make all these different methods for the banking system class (not sure how that will work, they are supposed to be private and the banking system is the class with the main STATIC method where they are supposed to be called . . . static can't call a private, right?). one is a data base reader method and one is a client setter. i guess that is supposed to set the info into the array.

    i was TRYING last night for a few hours to write the file reader method and the set client [] method. whe set client method will contain a for loop and will be inside the file reader method which will have a while loop.

    but i am getting all mixed up as to how to put the stuff IN the array. i know it will be tokenized and i can do the next token thing, but i am missing something here and i am unsure as to how to WRITE the line that creates each client [].

    HELP!!! if anyone wants to tackle this one and give me some help . . . i just can't tell you how much i need it. i will put up what i have so far in the next post. i have the homework guidelines in this one. it has the list of methods we are supposed to write.

    thanks
    crq
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2004
    Posts
    92
    here's what i have so far. i know it is really bad, but . . . that's why i am asking for help.

    PANIC!!!

    also, my array will be
    Client[]clients = new Client[]

    not sure if i declared it right or if it is supposed to be declared where it is . . . ?

    AND the Client class has an object account that is of the Account class and has several variables in it. i am trying to AVOID having to make an account array . . . i won't have to do that will i?

    thanks
    crq
    Attached Files Attached Files

  3. #3
    Join Date
    May 2004
    Posts
    219
    Client[]clients = new Client[]
    You have specify a size when creating a new array:
    Code:
    Client[]clients = new Client[10]

  4. #4
    Join Date
    Jul 2004
    Posts
    92
    right.

    Client[]clients = new Client[index].

    no problemo there.

    am i created an index variable that i will get from the numClients variable that comes from the database. the first line is numClients. and i will just set index to numClients - 1.

    am i creating this array OUTSIDE the method? putting it under where i have created
    Account accout = new Account ( . . . . . . )
    Client client = new Client(. . . . .)

    ?

    tanks
    crq

  5. #5
    Join Date
    Jul 2004
    Posts
    40
    Sorry crq, very busy at work today, just have a little time to address this but wanted to add my 2 cents.
    About the account array: You shouldnīt have to make an account array because, as far as I am concerned, every Client object should contain an Account object because each client has an account. Maybe you will need to change this later so that each Client can have more accounts.
    If you have an Account in the Client class, you can then access your array using Client[0] or something and then you can access the account by using:
    Code:
    Client[0].getAccount().toString();
    I think this works, or you may have to store the Client temporarily to access the values like:
    Code:
    Client tempClient = Client[0];
    int accountBalance = tempClient.getAccount().getAmount();
    String accountSummary = tempClient.getAccount().toString();
    This is just an idea, donīt have to do it this way I guess.
    I think, therefore I am....... I think.

  6. #6
    Join Date
    May 2004
    Posts
    219
    Originally posted by crq
    and i will just set index to numClients - 1.
    Wait, why -1? Arrays are defined by size, not their maximum index.

  7. #7
    Join Date
    Jul 2004
    Posts
    92
    thanks!! you are correct!!

    good thing my finger isn't on the button, huh!!??!!??

    crq

  8. #8
    Join Date
    Jul 2004
    Posts
    92
    ok, our assignment got changed again. we now have to write a BankDatabase class to hold our Client array called clients[]. he has given us the skeleton of the class, though, including the method headers that we are to use to create the methods.

    it will be read from a file. the file first contains the number of clients N, and the next line contains the system administrator password. the next lines are client info that look like this . . .
    M.J.,Waston,111111111,1,1,1,3000.0,2222

    see if you think this looks ok for reading each line into one instance of the array clients[].

    public boolean readFile(String _dbFileName) throws FileNotFoundException, IOException
    {
    // open the database file to read
    BufferedReader inFile = new BufferedReader (new FileReader (_dbFileName));
    String inStr = inFile.readLine();
    // the first line is the # of clients
    int N = Integer.parseInt(inStr);
    // the second line is the administration password
    adminPassword = inFile.readLine();
    clients = new Client[N];
    StringTokenizer strAnalyzer = new StringTokenizer(instr, ",");
    for (int index = 0; index<N; index++);
    {
    inStr = inFile.readLine();
    firstName = strAnalyzer.nextToken();
    lastName = strAnalyzer.nextToken();
    ssn = strAnalyzer.nextToken();
    accNumber = strAnalyzer.nextToken();
    accType = Byte.parseByte(strAnalyzer.nextToken());
    accStatus = Byte.parseByte(strAnalyzer.nextToken());
    accAmount = Float.parseFloat(trAnalyzer.nextToken());
    pin = strAnalyzer.nextToken();
    clients[index]= new Client(firstName, lastName, ssn, accNumber,
    accType, accStatus, accAmount, pin);
    }
    // close the input file
    inFile.close();
    return true;
    }


    does that get it done you think? should i do anything for the boolean being false? why should it even return a true value?

    thanks
    crq

  9. #9
    Join Date
    Feb 2004
    Posts
    541
    you need to be catching an IOException in there I would think. When you read/write from/to streams then there's a chance something will go wrong and it will throw an IOException. If you catch an IOException the method would return false (because the file couldn't be read), otherwise it returns true because the file was read fine. Also, if it read the wrong file then it would fail at parsing it as it wouldn't be in the correct format, so it would return false then also.

  10. #10
    Join Date
    Jul 2004
    Posts
    40
    It helps to return a boolean value because you can use this method in an if construction like:
    Code:
    if (readFile(String _dbFileName))
    {
        do whatever
    }
    else
    {
       System.out.println("The dbFile could not be read!");
    }
    I think, therefore I am....... I think.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center