Question
Sometimes people have their initials printed on things like towels, shirts, and glassware. These initials are called a monogram. You are to write a class
Sometimes people have their initials printed on things like towels, shirts, and glassware. These initials are called a monogram. You are to write a class Monogram which represents a person's initials. A Monogram class has String instance variables of a first name, middle initial (one letter without period), and last name.
There is no starter file. You will write the whole class and provide Javadoc for the class, the constructors and the methods.
The Monogram class has two constructors (This is called overloading).
- public Monogram(String theFirst, String theMiddleInitial, String theLast) initializes the instance variables with the values of the parameters. The user is supposed to supply a single character for theMiddleInitial. But users often do not do what they should. A good program protects itself from user errors. So use the substring method to get just the first character of theMiddleInitial and store that in the instance variable. Now your program will work, even if the user makes a mistake by entering more than one character for theMiddleInitial.
- public Monogram(String theFirst, String theLast) initializes the first and last names to the given parameters and initializes the middle initial to the empty String (two double quotes with no space like this "")
The class has the following methods
- public String getFirstName()
- public String getMiddleInitial()
- public String getLastName()
- public String getName() Gets the full name. There is a single space after both the first name and the middle initial. So there will be two spaces between first name and last name when there is no middle initial.
- public String getMonogram() Gets the letters comprising the initials (first initial, middle initial, last initial) with no spaces.
Requirement: Do not use an if statement inside method getMonogram. The middle initial is either a string of one character of the empty string.
To get the first letter of a string, you can use substring
String firstLetter = word.substring(0, 1);
For the draft, provide the instance variables and the first constructor. Implement these methods: getFirstName, getMiddleInitial, and getLastName methods. Implement the other methods as stubs. Provide Javadoc. For the stubs, indicate what will be returned in the final not null.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started