Write a class named full name. Each object of type full name should represent a
ID: 3578893 • Letter: W
Question
Write a class named full name. Each object of type full name should represent a person's first, middle, and last name. The constructor should accept three String arguments. The class should also provide methods for creating various display strings. The class might be used like this. The class should have the following constructors and methods. public Fullname (String f, String m, String 1) Three argument constructor public String longDisplayString() - Returns a single string with the first, middle, and last name separated by spaces(e. e. Helen Adams Keller") public String shortDisplayString() Returms a single string with the first name, middle initial followed by a period, and last name. All separated by spaces (i.e, "Helen A. Keller") Use any members that you find necessary, Write only the class. No main method.Explanation / Answer
Code:
class Fullname
{
String first,middle,last;
Fullname(String f,String m,String l)
{
first =f;
middle=m;
last=l;
}
String longDisplayString()
{
return first +" "+ middle+ " "+last;
}
String ShortDisplayString()
{
return first+ " "+ middle.charAt(0)+" "+ last;
}
String monogram()
{
return first.charAt(0)+" "+middle.charAt(0)+" "+last.charAt(0);
}
int length()
{
return first.length()+middle.length()+last.length();
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.