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
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education