1

メニューを提供するプログラムを作成しています:

 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. 電話番号
  4. 勘定残高

何が含まれているかは推測できると思います...

すでに新しいレコードを追加しているとします。

ノードを変更または削除するときにノードを選択したままにする方法を作成する方法を見つけようとしています。

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*/
}

私は見つけた説明を理解しましたが、これらの説明には、実際にこれを達成するのに役立つ構文はありません。誰かがそれがどのように行われたかを教えてもらえますか?

4

1 に答える 1

1
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);
        }

    }
于 2013-03-28T03:50:48.897 に答える