You have made a good start; I presume you are correctly reading each line? Have you verified that? The code looks OK for that.StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.
All things are lawful, but not all things are profitable.
Actually, if you have the name of the character as a line by itself, that makes it easier to parse:- if (line.equals("ROMEO")) ... It will be really awkward if the Bard has a character called SceneKnute Snortum wrote:. . . If it looks like this then I don't think it will work at all. But maybe thelovers.txt is formatted differently. . . .
Anthony Giggs wrote:This is the Assignment:
You will write a Java program AnalyseText.java that will do the following:
– initialise the variables that you will need to store all the information below;
– read the file theLovers.txt, line by line;
– count the number of lines in which Romeo says “Juliet”;
– count the number of lines in which Romeo says both “Juliet” and “love” (note that the word “love”
may start with an upper-case or a lower-case letter);
– count the number of lines in which Juliet says “Romeo”;
– count the number of lines in which Juliet says both “Romeo” and “love”;
– count the number of scenes;
– in each scene, check if Romeo and Juliet are both present and, if that is the case, update the
variable that counts the number of those scenes;
– print all the relevant variables in a human-readable form.
My code seems to be quite weird and I'm not sure if the values it gives me are correct. Any suggestions are fine, even if I have to change my whole code.
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|