Ask 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 are string type and the middle initial is a character type (single initial character)

+5
Answers (1)
  1. 11 December, 13:36
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers