Write a class named Initials that stores three char values o

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.”

Solution

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;
   }
}

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 constr
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 constr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site