After an hour of browsing the web, I decided to ask for help for my IB project (can't paste my whole code or I'll be cheating off myself). I don't have much experience, so please explain whatever syntax your solution may have (please don't say rewrite the whole thing).
Anyway, I decided to write a program that will store user information such as name, number and notes on them. I created a hashmap called accounts and used the following code to add new infomation
Record temp = new Record();
temp.name = nm;
temp.number = nb;
record.add(temp);
Object t = (Object)nm;
accounts.put(t, temp);
/*
Record is a class i created to store the stuff, nm and nb i got from user input. record is an Arraylist that i'm not sure i need later.
*/
To edit something, say the phone number i add this to the above
temp = accounts.get(t);
temp.number = nb;
accounts.put(t, temp);
Now is there a way I can check if t (the name) is already in the account hash map? I realized this is a problem after I accidentally typed a non-existent name and the output was weird.
Also, I need some advise on how to write the info to a text file. I was thinking of just adapting this code my teacher gave us and separating the different variables with symbols that acts as tokens.
try
{
PrintWriter pw = new PrintWriter( new FileWriter(
new File( "FileName.txt" )));
for(int i = 0; i<SIZE; i++)
pw.println( ""+ array[ i ]);
pw.close();
fileB = true;
}catch(IOException e)
{
JOptionPane.showMessageDialog(null,
"ERROR in fileArray()\n"+e);
}
My question is how do I erase and edit the text file when I edit information? (eg, what where and what type of search?)I plan to write to the text file before exit and read it when the program start.
Also, what kind of loop should be used if i want to be able to restart a certain process if wrong information is typed? For example, i'll have a conformation message, and if it's no i want to be able to go back to the start of that process. I know java don't have flags so...
Anyway, I'll appreciate any help I can get, thanks.