Мне нужно заменить все вхождения именем, данным пользователем, новым именем.Вот мой код:
public class Person
{
public Person() {}
public Person(String name, String address, String email, String phone)
{
this.name = name;
this.address = address;
this.email = email;
this.phone = phone;
}
String name = "";
String address = "";
String email = "";
String phone = "";
public String toString()
{
return "Name: " + name + " Address: " + address + " Email: " + email + " Phone: " + phone;
}
}
class Student extends Person
{
public Student() {}
public Student(String studentName, String studentAddress, String studentEmail, String studentPhone)
{
this.studentName = studentName;
this.studentAddress = studentAddress;
this.studentEmail = studentEmail;
this.studentPhone = studentPhone;
}
public String toString()
{
String studentInfo = super.toString();
return studentInfo.replaceAll(name, studentName);
}
//int grade = 0; COME BACK TO THIS
String studentName = "";
String studentAddress = "";
String studentEmail = "";
String studentPhone = "";
public static final int freshman = 0;
public static final int sophomore = 1;
public static final int junior = 2;
public static final int senior = 3;
}
Сейчас он заменяет каждую букву именем, которое передает пользователь.Как я могу заставить его заменить только фактическое имя?