I'm having trouble figuring out a few different methods that I'm putting into a constructor. Any chance for advice?
I'm having trouble with the last 3 near the bottom. I want to compare two name variable to each other to see if they are the same regardless of case, then I want to take just the first initial from each name that the user inputs, and last I want to count the amount of characters not counting spaces. The user inputs their name as First Middle Last. I am lost.
Thanks in advance.
/* import the Scanner class */
import java.util.Scanner;
class Name {
String first, middle, last;
public Name(){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your first name: "); //gets first name
first = scanner.next();
System.out.print("Enter your middle name: "); //gets middle name
middle = scanner.next();
System.out.print("Enter your last name: "); //gets last name
last = scanner.next();
System.out.println(first + " " + middle + " " + last); //prints First Middle Last names
}
public String getFirst(){
return first;
}
public String getMiddle(){
return middle;
}
public String getLast(){
return last;
}
public String firstMiddleLast(){
return (first + " " + middle + " " + last);
}
public String lastFirstMiddle(){
return (last + "," + first + " " + middle);
}
public boolean equals(){
return (name1.first.equals(name2.first) && (name1.middle.equals(name2.middle) && (name1.last.equals(name2.last))));
}
public String initials(){
return (charAt(0) + charAt(" " + 1) + charAt(" " + 1);
}
public int length(){
return ();
}
}