title: java how to replace variables in a method
body: <p>I need to replace all occurrences with the name that is given by the user with the new name.
  Here is my code:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>Right now it replaces every letter with the name that the user passes.  How can I get it to only replace the actual name?</p>