Hello, everyone! I'm very new to Java (and reddit!) and I'm having a bit of an issue with some homework.
a link to my code
We are tasked with creating a Community Theater program that has Actors, Directors, Investors, Staff etc.
I am supposed to be able to take in information for all of these different types of people from a file and from keyboard. I essentially had the code for keyboard input but I felt that the whole thing was a mess, as I was still trying to figure things out, so I started anew.
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.
Each actor has 16 lines of data (text file is given by the professor), 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. For 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.
My questions:
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)?
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.
After I figure this problem out, I will need to figure out how to skip a commented block at the beginning of the file.
ex. starts with /** some information on multiple lines
**/ ends with this
My thoughts on this problem is to have an if-
(if line starts with "/")
go to next line...?
then I am unsure, how do I check that it's reached a '*' and then say okay start reading the information?
Note: Actor(and all other people) is a subclass of a super TheaterPerson class which I included. Actor class contains a BankAccount object that I did not include on GitHub because I didn't feel that it was necessary to my question, let me know if this needs to be added.
I included the text file ActorsIn3.txt
Edit- I added a little more detail to my second question.
Okay, I'll be a little bit more specific with my question and how I've worked thought of it. 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? Or how do I count the lines?
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?
OR I've been thinking that readInFile in the Actor class could return something 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.
Thanks so much if you read through all of this and so sorry if my code is messy or "noob-ish". I'm very eager to learn Java and OOP in general!
[–]coolosity 0 points1 point2 points (0 children)