• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Manipulation  RSS feed

 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I need help with this assignment. From all the assignments so far this semester, I've hit a road block on this one. This is a two part assignment. I don't know how to even start on this.

This is the assignment.

Objectives
1. To be able to use String methods.
2. To implement a simple class.

Overview
A name-formatter accepts a complete multi-part name and provides methods to obtain the name in various formats. For example, given a complete name “Jack Bee Quick Nimble”,
the formatter provides methods to obtain the first, second and last names, the full name, the brief name and the list name:
FIRST : Jack
SECOND : Bee
LAST : Nimble
FULL : Jack Bee Nimble
LIST : Nimble, Jack B.
BRIEF : J. B. Nimble
INITIALS: JBN
The formatter ignores all except the first, second and last names. If the complete name has only 1 part, it is interpreted as the first name. If there are exactly 2 parts, they are interpreted as the first and last names.

You are provided with a skeletal NameFormatter class, and a completed simple client class to test your implementation.

Specific Requirements
1. A completed client main() is provided. Make no changes to the client.
2. A partially completed NameFormatter class is provided. Follow the comments to complete the constructor and other class methods.
3. Provide any private (helper) methods you find useful.
4. The constructor must always initialize all instance variables, even if to null.
5. The values of the instance variables must be “in standard form”: first letter uppercase, all other letters lowercase.

We make no changes to this one.



The modification goes here.



 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you understand from the requirement?
It gives your an example and what you need is to implement the logic to achieve the expected result.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Despite what you can read in many books, only ever use \n if you have been explicitly told to provide LF. There is a bit of explanation here (in a note between two horizontal lines). The reason is that different OSs use different line ends: Mac (old: you will probably never use such an old Mac): \r Linux and Unix and newer Macs: \n DOS/Windows®: \r\n
I recommend you use a Formatter, which hides behind the String#format method, to create that output String.
Why are you using JOptionPane for keyboard input? That is very old‑fashioned programming.

To get the logic, you write it down on paper, then you can covert it to code later.
 
Steve Wilson
Greenhorn
Posts: 4
Eclipse IDE jQuery Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:

Why are you using JOptionPane for keyboard input? That is very old‑fashioned programming.


This is what they teach in school when you are first starting out playing in the console. JAVA 101- they like to teach it like this first and then maybe they move to something else once they get to GUIs or JSPs. Darn teachers are always behind the times, I am still catching up.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scanner was introduced over 9 years ago.
 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raymond Tong wrote:What do you understand from the requirement?
It gives your an example and what you need is to implement the logic to achieve the expected result.


I basically don't even know how to start with this. :/ Any pointers?
 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody please explain to me what do I do with the constructor, and also explain to me the 1 name part code.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means you need to use the constructor to divide the String entered into tokens using whitespace as their separtor, and use that technique to initialise the first name and last name fields.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!