Question:
Java Programming- how to fix names (upper case, last name first)?
paintballer100
2010-09-13 09:38:29 UTC
Hey guys. So our recent project in my Java programming class is to have this program read a data file, and then it would print out the names of the students with their grades. Our project, however, was to make it fix the names by making the first letter capital, and the rest of the name lower case, as well as have their last name print first, followed by a comma, and then their first name. I have no idea how to work this out. I'm so out of practice for Java that I dont even know how to start.

The only clues he's given us is to use indexof to find the commas, use vectors, and then use the toUpperCase to make the whole word upper case, and then use toLowerCase to lower everything but the first letter.

It is comprised of two classes. I will include links to pastebin.com to show you code.

First_314_Project class-
http://pastebin.com/9JR5Ug6N

Person class-
http://pastebin.com/TW28RbVT

It reads from a file called DATA314 and I will host it for download here-
http://www.mediafire.com/?fwhszrrh6oakb6a

Any help you can give would be greatly appreciated. Like I said, I have no idea where to even start. I'm not sure how to even use vectors or indexof. Also, we have to fix the scores. More detailed instructions are commented out in the Person class.
Three answers:
?
2010-09-14 14:09:50 UTC
You can use the following method to make a given string's word's first letters capita.



public static String formatFirstName(String input) {

input = input.trim();

String output = "";

String s = "";

for (int i = 0; i < input.length(); i++) {

s = "";

if (i == 0) {

s += input.charAt(0);

output += s.toUpperCase();

} else if (input.charAt(i) != ' ') {

s += input.charAt(i);

output += s.toLowerCase();

} else {

output += " ";

s += input.charAt(i + 1);

output += s.toUpperCase();

i++;

}

}

return output;

}
2016-04-21 23:51:31 UTC
Jimmy Moon Riley Moon Ethan Moon Trevor Moon Hailey Moon Christie Moon Piper Moon Lauren Moon Samuel Moon Taylor Moon Megan Moon Tina Moon Melanie Moon David Moon Congrats!
?
2010-09-15 08:53:09 UTC
I suggest for all your java programming questions/programs/homeworks you visit http://www.homeworkjava.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...