I have to do a really strange thing.
I have to take a string of 2 words and then separate it and put it into two other strings eg
String name = "fred blogs";
move the part of the string name which says fred to the String firstname so it is like this:
String FirstName = "fred";
Move the second part of the string blogs to the String LastName;
String LastName = "blogs";
this is my code for it so far. I cannot quite work out the loops. When I test it I only get null values for printing the getter methods ( i test it in a separate class) the bit is bold is the bit I am having problems with.
import java.lang.Object;
public class Name
{
// ATTRIBUTE GO HERE
String FirstName;
String LastName;
String name = "Piers McMurdock";
public Name(String Firstname, String LastName)
{
for( int i = 0; i < name.length(); i++)
{
while (name.charAt(i) == ' ')
{
if (name.length() < name.charAt(i))
{
name = Firstname;
}
else if (name.length() > name.charAt(i))
{
name = LastName;
}
}
}
}
public Name( String name)
{
name = FirstName + LastName;
}
public String getFirstName()
{
return FirstName;
}
public String getLastName()
{
return LastName;
}
}