Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.1 kB
3
Indexable
Never
public class Name {
   private String first, middle, last;

   // Constructor
   public Name(String first, String middle, String last) {
      this.first = first;
      this.middle = middle;
      this.last = last;
   }

   // Get normal order
   public String getNormalOrder() {
      return first + " " + middle + " " + last;
   }

   // Get reverse order
   public String getReverseOrder() {
      return last + ", " + first + " " + middle;
   }

   // Get first name
   public String getFirstName() {
      return first;
   }

   // Get last name
   public String getLastName() {
      return last;
   }

   // Get middle name
   public String getMiddleInitial() {
      return middle;
   }

   // Set first name
   public void setFirstName(String first) {
      this.first = first;
   }

   // Set last name
   public void setLastName(String last) {
      this.last = last;
   }

   // Set middle initial
   public void setMiddleInitial(String middle) {
      this.middle = middle;
   }

   // toString method
   @Override
   public String toString() {
      return first + " " + middle + " " + last;
   }
}
Leave a Comment