Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named Initials that stores three char values, one for the first, m

ID: 3925678 • Letter: W

Question

Write a class named Initials that stores three char values, one for the first, middle, and last initials of a person. The class should have the following constructors and methods

A three argument constructor that could be used to create an Initials object like this (For, perhaps, Franklin Delano Roosevelt) :

A setter for each initial

x.setFirst(‘M’);

x.setMiddle(‘J’);

x.setLast(‘F’);

And a toString method that return the three initials, each followed by a period (‘.’) and a space.


x.toString() would return “M. J. F.”

Explanation / Answer

Initials.java


public class Initials {
   private char first;
   private char middle;
   private char last ;
  
   public Initials(char f, char m, char l){
       this.first = f;
       this.middle = m;
       this.last = l;
   }

   public char getFirst() {
       return first;
   }

   public void setFirst(char first) {
       this.first = first;
   }

   public char getMiddle() {
       return middle;
   }

   public void setMiddle(char middle) {
       this.middle = middle;
   }

   public char getLast() {
       return last;
   }

   public void setLast(char last) {
       this.last = last;
   }
  
   public String toString(){
       return first+". "+middle+". "+last;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote