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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education