I need to validate the inputs of the first name and lastname.
I think the clone portion is ok, but I don't know how to combine the last and firstname for the input information so it is easy to validate.
public Clone() {
}
}
class Person implements Cloneable{
private String firstname;
private String lastname;
@Override
public Object clone() {
Person person = new Person();
person.setFirstname(this.firstname);
person.setLastname(this.lastname);
return person;
}
public void setFirstname(String firstname){
this.firstname = firstname;
}
public void setLastname(String lastname){
this.lastname=lastname;
}
public String getFirstname(){
return firstname;
}
public String getLastname(){
return lastname;
}
public static void Person(){
String Fname ="";
String Lname="";
Scanner input2 = new Scanner(System.in);
Scanner input3 = new Scanner(System.in);
Person person = new Person();
int i = 2;
char c;
/* This will take the values of first name
and last name.
*/
if (input2.nextLine().length()<=6) {
System.out.println("Enter your First Name:");
Fname = input2.nextLine();}
else if (input2.nextLine().length()>6){
throw new InputMismatchException();}
System.out.println("Enter your Last Name");
Lname =input3.nextLine();
person.setFirstname(Fname);
person.setLastname(Lname);
/* This method will produce firs and last name
also will produce the introduction.
*/
Person cloned = (Person)person.clone();
//** This method will print welcome to the world of Java.
Introduction();
System.out.println(cloned.getFirstname()+ " " + cloned.getLastname());
System.out.println("*******************\n\n");
}
Aucun commentaire:
Enregistrer un commentaire