I am trying to invoke a set method in a constructor that accepts user input to instantiate an object. A sample of a set method is as follows:
public void setName(String name) {
if(name.length()>0 && name.length()<25) {
this.name = name;
}
else {System.out.println("Name length can not exceed 25 characters.");}
}
I then want to accept the user input to instantiate the object. I currently have it formatted like so:
public Character(String name){ name = setName(input.nextLine());}
I have imported the scanner and created a scanner object. The character constructor itself is actually quite large, it consists of 29 variables, each of which have a set method similar to the first code sample.
My ultimate goal is to put this in a GUI form for a person to fill out. The error Eclipse gives for my current syntax is "type mismatch, cannot convert from void to String".
How is this supposed to be done?