Ask Question
4 February, 12:28

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)

+3
Answers (1)
  1. 4 February, 13:26
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers