If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

help with a java program

I need to create a program that will read names and phone numbers from a text file. I then need to search for a phone number by providing a last name, I will also need to be able to add a name and phone number and also be able to delete a name and a phone number.

Can anyone help me please?

This is what I have so far:

File file = new File("phones.txt");

try {

scanner = new Scanner(file);

while (scanner.hasNextLine()) {

String line = scanner.nextLine();

System.out.println(line);

}//end of while

} catch (FileNotFoundException e) {

e.printStackTrace();

}

All this does is read from a text file and then print the names and phone numbers. I need to be able to search for similar last names in that text file and provide the full names and phone numbers for that last name. I really need help with this !!

Are you assured of the file structure of the text file? Is there a delimiter contained in each line?

Do you understand what the Scanner class does with the records that you read in? Do you know that you can use methods of the class to capture each part of the imput line and have a String which can be used by your program?

How are you going to interface with the user to ask how he/she wants to use it at that time?

How are you going to store the data read from the input file (what data structgure are you going to use?) What is your plan of attack for finding the right name and phone number? For adding a new entry to your collection

help with a java program

Well I do have a plan and i am doing good so far,
but what i need this time is to be able to read just a part of the string.
for ex:
Smith;John;3337122

i need to be able to read just smith and then read just john and then the phone number. is there something i could use to recognize the semi colon and just read what's in front of the semi colon and do the same for the second name.

the other problem i have is when i add a record on the file, the originals get lost, how do i add a record without losing the original records?

Do you know how Scanner works? By default, it will make an array of stings delimited by a NewLine/Enter code. So each entity in the array will be a sting of a line like "Smith; John; 337122". You can then have another Scanner object which will delimit based on the semi-colon that separate the "words" of the line. You will then have an array that is [Smith John 337122]. Then, while (hasNext() ) { next(); then assign to a variable to be included in your entry in your data structure } will read each item.

You need to store your records in a data structure as you read them. What kind of data structure will give you the functionality that you need.

It sounds as if you are writing to a file on a disk - is this right? If so, you want to open your output file "to append". There is usually a boolean switch for the API classes which write files to set "append" to "true". The default is false so it will write at the start of the file - erasing the old content - rather than the end of the file.

Are you required to write sequentially to disc? Isn't it better to have entries kept in memory so you can work more quickly with them? Are you really set up to read and write directly to disc?

I don't think so. I will help you with concepts. I will look over code. I will even correct or suggest some content. I will not write the project for you so you can represent to whomever it is that you are submitting the project that it is your work.