簡體   English   中英

如何在選擇的鏈表中保留節點以進行編輯和/或刪除?

[英]How do you keep a node in a linked list selected for editing and/or removal?

我正在制作一個程序,為您提供菜單:

 1. Show all records. 
 2. Delete the current record 
 3. Change the first name in the current record 
 4. Change the last name in the current record 
 5. Add a new record 
 6. Change the phone number in the current record 
 7. Add a deposit to the current balance in the current record 
 8. Make a withdrawal from the current record if sufficient funds are available. 
 9. Select a record from the record list to become the current record. 
 10. Quit

和命令提示:

Enter a command from the list above (q to quit):

我有4個鏈接列表:

  1. 名字
  2. 電話號碼
  3. 賬戶余額

我確定您可以假設它們包含的成分...

假設我已經添加了一條新記錄。

我試圖弄清楚如何制作一種方法來在更改或刪除節點時保持選中狀態。

public void numberNine()
{
    System.out.println("Enter first name: ");
    String fName = keyboard.next();
    System.out.println("Enter last name: ");
    String lName = keyboard.next();
    if(firstName.contains(fName))
    {
        if(lastName.contains(lName))
        {
           /*I need to set the current record here.
           I also need to print out the current record.
           That means I need to find the corresponding
           information from the linked lists by checking
           the index of the first or last name because
           both share the same index position for the
           correhlating information of the selected person
           for the current record.*/
        }
        else
        {
            System.out.println("No matching record found.");
        }
    }
    else
    {
        System.out.println("No matching record found.");
    }
}

唯一的是,我對完成工作所需執行的語法並不完全熟悉,但是從環顧四周了解到的信息來看,我可能需要一種看起來像這樣的方法:

public void currentRecord(String fName, String lName)
{
    /*check for index of both fName and lName between the two strings containing
      this information until they match up, then select the telenumber and 
      balance that match the index of the fName and lName and print*/
}

我已經了解了所找到的解釋,但是這些解釋沒有任何語法可幫助我實際實現這一點。 有人可以告訴我如何完成嗎?

private static void searchRecord(String firstName, String lastName) {
        boolean recordFound = false;
        if(fName.contains(firstName) && lName.contains(lastName)){
            int index = -1; 

            for (String fn : fName) {
                index++;
                if(fn.equals(firstName)){
                    String ln = lName.get(index);
                    if(ln.equals(lastName)){
                        recordFound = true;
                        System.out.println("Record Found");
                        System.out.println("First Name="+ fName.get(index));
                        System.out.println("Last Name="+ lName.get(index));
                        System.out.println("Phone="+ phone.get(index));
                        System.out.println("Balance="+ balance.get(index));
                    }
                }
            }

        } 
        if(!recordFound) {
            System.out.println("No Record found for first name="+ firstName + " and last name="+lastName);
        }

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM