Reputation: 11
basically i have this java assignment in which I need to take the following text file: https://drive.google.com/file/d/1NqWtApSHovOfSXzVCeU_GPtsCo_m6ZtJ/view?usp=sharing
The legend for the text file is here: E: did the elector result in promotion (1) or not (0) T: time election was closed U: user id (and screen name) of editor that is being considered for promotion N: user id (and screen name) of the nominator
And create the following two methods:
Given a user id, output the total number of times the user has voted to support or be neutral or oppose the candidate considered for promotion for all people the user has voted for collectively in all the elections.
Given a user id considered for promotion, output the user id and screen name of the nominator. For multiple nominations, you will output all nominators. If the user is not nominated ever, output an appropriate message.
I'm really lost on how I should go about splitting the text file into pieces to help me obtain the information needed to create the two methods. Any insight would really be great
Upvotes: 0
Views: 220
Reputation: 1
You can use the str.split() method. You write the point in the text at which you would like to split in the brackets. For example if you have the following;
String str "Hello world";
String [] arrayString = str.split (" ");// splits the string at the space
for( String a:arrayString);
System.out.println(a);
Output:
Hello
World
Upvotes: 0
Reputation: 5119
Basically you need to create different string reader loops that iterate over the text file line by line. Nobody here will do this for you because it´s to much work, and it´s your work!
Here´s a discussion about iterating-over-the-content-of-a-text
Upvotes: 1