• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with this array  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I'm working on an array on Java and I need it's really confusing me.
I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.
I've created two classes



This isn't completed yet, but so far it doesn't work. So please, I don't want the answer right away to this problem but an understandable way to do this so I can get it.
=-)
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't look at the whole thing but your first call to substring() passes in the length of the array not the length of the name.
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Reem Akira wrote:I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.

In your example, shouldn't "Smith" return "T. H. Smith" because capitalize last character (H) and the next to last (T) of the last name?


 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reem, welcome to the ranch.

You didn't quite get the code tags right in your post so I have added them properly for you. You need to highlight the code before clicking the code tags button. If you are still not sure you can read the tutorial on how to UseCodeTags.
 
Reem Akira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:Hi Reem, welcome to the ranch.

You didn't quite get the code tags right in your post so I have added them properly for you. You need to highlight the code before clicking the code tags button. If you are still not sure you can read the tutorial on how to UseCodeTags.


Thank you.
 
Reem Akira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Welcome to the Ranch.

Reem Akira wrote:I have to input last names using the dialog box and store them into an array. Then take that array, loop through it to get the last character of the last name and the next to last and capitalize those characters.
Example "Smith" should return H. S. Smith, then store the new formatted names into an array and return that array.

In your example, shouldn't "Smith" return "T. H. Smith" because capitalize last character (H) and the next to last (T) of the last name?




Yes, indeed it is "T. H. Smith" That was a typo. Other thing is that I decided to use an initializer list instead of having an user inputting the names, to make it easier. Though my code still doesn't work. The output is ....not what I expected
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so write out exactly what you would do if you were doing it yourself before writing any code. ie:

Read the last letter in the name.
Convert it to upper case
Write it down
Write down a full stop
Read the second from last letter in the name.
Convert it to upper case
Leave a space and write it down
Write down a full stop

I'll leave you to finish this off.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!