Ask Question
27 September, 11:06

Create a class that represent a person's name with the first, middle initial, and last name (eg "John K. Henry"). The first and last names are string type and the middle initial is a character type (single initial character)

+1
Answers (1)
  1. 27 September, 12:17
    0
    public class PersonName {

    private String firstName;

    private char middleInitial;

    private String LastName;

    public PersonName (String firstName, char middleInitial, String lastName) {

    this. firstName = firstName;

    this. middleInitial = middleInitial;

    LastName = lastName;

    }

    public String getFirstName () {

    return firstName;

    }

    public void setFirstName (String firstName) {

    this. firstName = firstName;

    }

    public char getMiddleInitial () {

    return middleInitial;

    }

    public void setMiddleInitial (char middleInitial) {

    this. middleInitial = middleInitial;

    }

    public String getLastName () {

    return LastName;

    }

    public void setLastName (String lastName) {

    LastName = lastName;

    }

    }

    Explanation:

    Using Java Programming Language;

    The class is created called PersonName The class fields are firstName, MiddleInitial and LastName all declared as private to enforce encapsulation. We also created getters and setters for all the fields as well as a constructor
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a class that represent a person's name with the first, middle initial, and last name (eg "John K. Henry"). The first and last names ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers