Write a class called Name that has one instance variable to store the full name of a person. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -. The class has one constructor that takes a parameter to initialize the instance variable. However, the parameter string could have spaces at either ends and the constructor must trim the extra spaces before assigning it to the instance variable. The class has the following methods.
Write a class called Name that has one instance variable to store the full name of a person. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -. The class has one constructor that takes a parameter to initialize the instance variable. However, the parameter string could have spaces at either ends and the constructor must trim the extra spaces before assigning it to the instance variable. The class has the following methods.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 7RQ
Related questions
Question
![vowels are aeiou. Ignore case. Both "a" and "A" are vowels, and both "b" and "B" are
consonants.
You can have only one if statement in the method and the if condition cannot have either
&& or ||. Do not use the switch statement, which is basically the same as an if statement
with multiple alternatives. Hint: call method contains().
public String initials() Gets the initials of the name. Do not use nested
loops for the method. Hint: Each word after the first is preceded by a space. You can use
the String method indexOf (" ", fromIndex) to control a while loop and to determine
where a new word starts. This version of indexOf() returns the index of the first space
starting at the fromIndex, and it returns - if the space is not found in the string.
Remember that the name does not have 2 consecutive spaces.
Each method can have at most one loop.
Do not use nested loops in
any
method.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F170cb9b5-2292-4ecc-9f24-3c60291ff66d%2F5784859f-a3ac-494b-ab79-1d6f771d9217%2Ffjkw9io_processed.jpeg&w=3840&q=75)
Transcribed Image Text:vowels are aeiou. Ignore case. Both "a" and "A" are vowels, and both "b" and "B" are
consonants.
You can have only one if statement in the method and the if condition cannot have either
&& or ||. Do not use the switch statement, which is basically the same as an if statement
with multiple alternatives. Hint: call method contains().
public String initials() Gets the initials of the name. Do not use nested
loops for the method. Hint: Each word after the first is preceded by a space. You can use
the String method indexOf (" ", fromIndex) to control a while loop and to determine
where a new word starts. This version of indexOf() returns the index of the first space
starting at the fromIndex, and it returns - if the space is not found in the string.
Remember that the name does not have 2 consecutive spaces.
Each method can have at most one loop.
Do not use nested loops in
any
method.
![Problem C
Write a class called Name that has one instance variable to store the full name of a person. A
name can have multiple words, separated by single spaces. The only non-letter characters in a
name will be spaces or -.
The class has one constructor that takes a parameter to initialize the instance variable. However,
the parameter string could have spaces at either ends and the constructor must trim the extra
spaces before assigning it to the instance variable.
The class has the following methods.
public String getName () Gets the name string.
public int consonants() Gețs the number of consonants in the name. A
consonant is any character that is not a vowel, the space or -. For this problem assume the](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F170cb9b5-2292-4ecc-9f24-3c60291ff66d%2F5784859f-a3ac-494b-ab79-1d6f771d9217%2Fw5j4g8r_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Problem C
Write a class called Name that has one instance variable to store the full name of a person. A
name can have multiple words, separated by single spaces. The only non-letter characters in a
name will be spaces or -.
The class has one constructor that takes a parameter to initialize the instance variable. However,
the parameter string could have spaces at either ends and the constructor must trim the extra
spaces before assigning it to the instance variable.
The class has the following methods.
public String getName () Gets the name string.
public int consonants() Gețs the number of consonants in the name. A
consonant is any character that is not a vowel, the space or -. For this problem assume the
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT