Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: need help urgently!!

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry need help urgently!!

    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 + ".";
     }
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: need help urgently!!

    Hello kimwheeler.

    Welcome to the Java Programming Forums.

    What are you stuck on exactly? You need to break this down for us and take it one step at a time.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. JAVA Coder required urgently-paid
    By sam_java in forum Paid Java Projects
    Replies: 2
    Last Post: January 15th, 2011, 04:04 AM
  2. Help needed urgently!!!
    By sonia11 in forum Loops & Control Statements
    Replies: 1
    Last Post: October 19th, 2010, 04:19 PM
  3. Reading from a text file. Help needed urgently.
    By TheAirPump in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 14th, 2009, 06:16 PM