Saturday, 24 August 2013

Java - scan string into array

Java - scan string into array

I'm trying make a Facebook user that can add friends into the array that
already has 5 existing friends, so the new added friends will continue
after the 5, and the size of the array is set to 200. I'm having trouble
with putting scanned information into array, as I can only preset the
information other than scanning in.
private void initializeFriends() {
//initialize the size of array:
friends = new Friend[200];
//initialize the first 5 objects(Friends):
friends[0] = new Friend("Rodney Jessep", "rj2013", "Brisbane", "hi!");
friends[1] = new Friend("Jaime Smiths", "abcd5432", "Sydney",
"how's going");
friends[2] = new Friend("William Arnold", "william1994",
"Brisbane", "boom");
friends[3] = new Friend("James Keating", "qwerty52", "Newcastle",
"Hey");
friends[4] = new Friend("Amy Richington", "IAmRichAmy", "Perth",
"Yo"); }
so after the procedure above I'm going to add a method called
addFriends(), that's where the scanner come in to put in data, but how do
I write the code after
Scanner in = new Scanner(System.in);
Especially with all the different elements stored in a friend (String
name, String username, String city, String message)?

No comments:

Post a Comment