Hello, everyone! I posted this question at stackoverflow but they commented that they couldn't help me.
Here is a link to my code.
I am trying to create a Community Theater program that has Actors, Directors, Investors, Staff etc. I should eventually be able to input the information for the people from both a file and the keyboard. I'm working on trying to take in multiple Actors from one file and adding them to an ArrayList of Actors. My code takes in only one actor right now.
I am trying to take in multiple sets of data for the same type of class but creating new instances after each set of data (16 lines). Each actor has 16 lines of data (text file included), so I was thinking that I would need perhaps a for loop but I am unsure of how and where to implement it. I am also unsure about adding these new actors to the Actor ArrayList. I'm a little shaky on the idea of creating multiple objects when it is unknown how many you need to create. Right now, I know how many Actors I need to add but it would be nice if I could learn how to expand that based on the user's needs.
- How can I write my program to know when it is done reading 16 lines and then initialize a new Actor (will expand to other people)?(expanded below)
- Eventually, I plan on using my theaterObj (an instance of CommunityTheater class), what if I wanted to move the readActorFile method to that class? Would that change the way I implement anything majorly? Would it still be a static method? I ask this because I want the Actors array to be a variable in the CommunityTheater class. I would extend this to adding actors to an ArrayList in a Play class which would be in CommunityTheater as well. So, essentially a CommunityTheater has different Play(s), and each Play contains a list of Actors.
I don't exactly know where I should put a loop (should I use a loop?) to read through each line, in readActorFile or in readInFile? How should I write this loop, as in, how do tell my program what line it's reading?
What I've been thinking is that I would have a loop:
for(countLine=0; countLine < 17; countLine++) or while(countLine<17) read all the info
and then an if(?)-
if(file has a next line)-I don't really know how to code this- start over with loop of reading information?
I don't know about the for loop, as I'm not sure how to "count" lines in a text file.
OR I've been thinking that readInFile in the Actor class could return something(true/false?) to let the method readInActor know that it's done reading, then readInActor can check to see if there's anything else in the file, if there is- it would call the readInFile in Actor class again to read in information... and so on. But again I am unsure of how to code this.
Which would be a better way to go about this problem?
Thanks if you read all of this, I know it's pretty long.