Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding and replacing elements in Linked List
    text
    copied!<p>I need to be able to search a Linked List for certain unique elements (username, password, email) and after finding these elements I need to go to the next node in the list and begin a series of statements allowing users to change profile information. For some reason my code just doesn't work and I have no idea how to fix it. Any help would be great!</p> <p><strong>How GUI Looks</strong></p> <p><img src="https://i.stack.imgur.com/wIIaV.jpg" alt="GUI"></p> <p><strong>Link to Account Class:</strong> <a href="http://pastebin.com/jnBrcnP1" rel="nofollow noreferrer">http://pastebin.com/jnBrcnP1</a></p> <p>So the User fills out the Required information and if they want to change profile information such as "Name" or "Gender" they change the information then set the ComboBox next to it to "Yes" then click the button "Save Settings".</p> <p><strong>Here is what the Linked List looks like:</strong></p> <pre><code>tobi tobi123 tobi@hotmail.com tobi Mixed Breed Male 1-2 Virginia Walking peppy peppy123 peppy@hotmail.com peppy Chihuahua Male 5-6 Virginia Eating </code></pre> <p><strong>Here is my button code:</strong></p> <pre><code>private void jButtonP1ActionPerformed(java.awt.event.ActionEvent evt) { //New Linked List created from file LinkedList&lt;Account&gt; account = new LinkedList&lt;Account&gt;(); try { read(account, "doggydates.txt"); } catch (Exception e) { System.err.println(e.toString()); } display(account); //user information String username = jTextFieldP3.getText(); String password = jPasswordFieldP1.getText(); String email = jTextFieldP4.getText(); String name = jTextFieldP1.getText(); String breed = (String) jComboBoxP4.getSelectedItem(); String gender = (String) jComboBoxP3.getSelectedItem(); String age = (String) jComboBoxP1.getSelectedItem(); String state = (String) jComboBoxP2.getSelectedItem(); String hobby = jTextFieldP2.getText(); //change combo boxes String passchange = (String) jComboBoxP13.getSelectedItem(); String emailchange = (String) jComboBoxP14.getSelectedItem(); String namechange = (String) jComboBoxP6.getSelectedItem(); String breedchange = (String) jComboBoxP7.getSelectedItem(); String genderchange = (String) jComboBoxP8.getSelectedItem(); String agechange = (String) jComboBoxP9.getSelectedItem(); String statechange = (String) jComboBoxP10.getSelectedItem(); String hobbychange = (String) jComboBoxP11.getSelectedItem(); //cancel combo box String accountcancel = (String) jComboBoxP5.getSelectedItem(); if(username.equals("") || password.equals("") || email.equals("")) // If password and username is empty &gt; Do this &gt;&gt;&gt; { jButtonP1.setEnabled(false); jTextFieldP3.setText(""); jPasswordFieldP1.setText(""); jTextFieldP4.setText(""); jButtonP1.setEnabled(true); this.setVisible(true); } else { ListIterator&lt;Account&gt; itr = account.listIterator(); while (itr.hasNext()) { Account item = itr.next(); if(item.getUsername().equals(username) &amp;&amp; item.getPassword().equals(password)) { if(passchange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.setDataAtCurrent(password); } } } if(emailchange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(email); } } } if(namechange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(name); } } } if(breedchange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(breed); } } } if(genderchange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(gender); } } } if(agechange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(age); } } } if(statechange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(state); } } } if(hobbychange.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.goToNext(); acc.setDataAtCurrent(hobby); } } } if(accountcancel.equals("Yes")) { for(Account acc : account){ if(acc.getUsername().equals(username)){ acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); acc.goToNext(); acc.deleteCurrentNode(); } } } } } String file_name = "doggydates.txt"; try { FileWriter fstream = new FileWriter(file_name); BufferedWriter out = new BufferedWriter(fstream); ListIterator itr2 = account.listIterator(); while (itr2.hasNext()) { Account element = (Account) itr2.next(); out.write("" + element); out.newLine(); } out.close(); System.out.println("File created successfully."); } catch (Exception e) { } } } </code></pre> <p><strong>Read Method:</strong></p> <pre><code>public static void read(LinkedList&lt;Account&gt; account, String inputFileName) throws java.io.IOException{ BufferedReader infile = new BufferedReader(new FileReader(inputFileName)); while(infile.ready()) { String username = readLine(infile); String password = readLine(infile); String email = readLine(infile); String name = readLine(infile); String breed = readLine(infile); String gender = readLine(infile); String age = readLine(infile); String state = readLine(infile); String hobby = readLine(infile); Account a = new Account(username, password, email, name, breed, gender, age, state, hobby); account.add(a); a.showList(); } infile.close(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload