Hey guys, I'm writing a program to read in input from a file and output it in a certain order on screen. For example, a name & a number, that will be sorted numerically or alphabetically. I thought I would first try to read in input from the cmd prompt & then work out the file input later. The problem I'm having is that when I store say 3 different names and their corresponding phone numbers, the program prints out the last name 3 times. I think the problem is in the while loop but I cannot figure out how to fix it. If anyone can help me I would appreciate it http://pastebin.com/mdg7FbBB
Console is not in standard java API
don't use instance method getInfo, use constructor and construct new object everytime, because now you just change values of same object and you store reference of same object in an array of names so that's why it prints only last name
I didn't use Console because it's NOT in standard API so I can't use it http://pastebin.com/CkfKbErG
I made assumption that first second and number is written in one line and seperated by space when you want to finish ending information enter and just press ctrl+d (at least for linux)
I guess this would work too http://pastebin.com/ZJvueHEZ I just create new object personName everytime in while loop but i think it's bad practise
Thanks so much, I forgot to mention about Console. In our university we use a class called Console to read information from the user. It took me a little while to understand what you did as I'm not very familiar with other forms of input yet but once I did, I tweaked my code and came up with this http://pastebin.com/Hddds0QU It now prints each individual line. Now I can move on to work on getting the program to sort it. So thanks very much :)
yeah it seems ok
Join our real-time social learning platform and learn together with your friends!