我正在编写一个程序,为您提供一个菜单:
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):
我有四个链表:
- firstName
- lastName
- teleNumber
- accountBalance
我相信你可以假设它们包含什么…
假设我已经添加了一条新记录。
我正试图找出如何使一个方法,将保持一个节点选中,因为我做更改或删除它。
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);
}
}