Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java: Programming - Transform Name

Write a program to redisplay a name, possibly transformed

This Java program will reformat a user's name. There are two cases that have to be handled: the trivial case of a single name, where the name doesn't have to be changed, and the case where the names must be rearranged.

Case 1 - Single name

If the user enters only one name, eg, Madonna, or Prince, display that name without changes.

   Input:  Madonna
   
   Output: Madonna

Case 2 - Change First Last into Last, First

If the name consists of a first and last name separated by a blank, you must transform it. For example,

   Input:   Michael Maus
   
   Output:  Maus, Michael

Using the String methods, transform this string into the last name, comma, first name format. Some useful string methods are indexOf and substring.

Iterative programming

A programming style that is extremely useful is called iterative programming. In this style you write a little bit of the program and run it. For example, start this with a program that does nothing in main. After that compiles and runs (and does nothing), add Java statements that read the input string (but don't do anything with it yet. Continue in this way with very small steps.

In this problem you will probably want to do the single name case first. When that is running you try the other, which requires an if statement and string methods.

Extra credit (sort of)

I don't allow more than the maximum score on a problem, however if you do extra work, it can cancel out points that were taken off for other reasons.

Capitalizing the names would be good extra credit for this program. You can easily use the Java functions to change the case to something standard.

   Input:   mIcHaEl mAuS
   Output   Maus, Michael

Input

You may use JOptionPane.showInputDialog(...), Scanner.nextLine(), or SavitchIn.readLine(). You must read both names together; you can't ask for the first and last names separately.

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.