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.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 7RQ
icon
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.
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
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Software Development
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT