Very stuck on a programming question!!
Data for a number of people is given as a string. The data for each person is given
by two fields, a forename and a surname separated from each other by a forward
slash character. The end of each person’s data is marked by a # character. The
following is an example of such a String:
George/Best#Eric/Cantona#Ryan/Giggs#Br…
Write and test a Java application containing a main method class called
ArrayOfStringsDemo and a class called Name.
Name is to have two fields, one for a forename and one for a surname, and should
include a constructor with formal arguments corresponding to the fields, an accessor
method for each field and a toString method.
In addition to the main method, ArrayOfStringsDemo should contain a static
method called findName which takes two arguments. The first argument is an array
of elements of type Name and the second argument is a Name. findName returns the
index of the element in the given array whose firstname and secondname are the
same as those of the Name given as the second argument. If a match is not found,
-1 is returned.
You main method should implement the following steps.
(a) Prompt for and read in an integer representing the number of firstname/secondname
pairs in a string to be input; store the input value in an int n.
(b) Prompt for and read in a String with the above format and containing n
firstname/secondname pairs.
(c) Construct an array of Names of size n called testArray.
(d) For each successive firstname/secondname in the input String, construct a
Name object and assign this to the next element in testArray.
(e) Use an appropriate selection of test Names to thoroughly test your findName
method.
This is what i have done so far....
public class Name { public String forename; public String surname; //Constructor with arguments corresponding to the fields. public Name (String givenForename, String givenSurname) { forename = givenForename; surname = givenSurname; } //Accessor methods for each of the fields. public String getForename () { return forename; } public String getSurname () { return surname; } //A toString method. public String toString () { return "\tForename:" + forename + ";\t" + "Surname:" + surname + "."; } }