尽管我没有解决上述问题,但我发现了一条有趣的捷径,可以实现我的目标。这就是我的管理方式:
我没有创建一个包含三个值(客户、帐户、交易)的字符串数组,而是创建了一个包含一个值的字符串。类帐户 Saving 和类帐户 Credit 可以访问来自 Saving 和 Credit 继承的类 Account 的交易方法。负责对象的银行逻辑有一个方法,其中客户的所有值都来自 Map;Map<Account, Customer> customerInfo = new HashMap<Account, Customer>(); . 换句话说,这里是seudo:
将交易添加到帐户。
向客户添加帐户。
将客户添加到列表中。
这是我的新 custFile 方法。
//列出具有字符串值的数组。列出对象= new ArrayList();
//------------------------------------------------------------------------------------------------
// Description: A method that creates and updates a list Array. The update works by choosing the first
// characters of the input and the existing string in the list and comparing them
// removing if equals and adding the last input containing the new values for the
// string. Adding a new string object otherwise.
// Arguments: Long for Id customer to be created or updated in the list.
// Return: An array list with the current database.
//------------------------------------------------------------------------------------------------
public void custFile(long iD) //, int acc, String trans )
{
String customer = bank.infoCustomer(iD);
System.out.println("\n\n\n" + " String with three values" + "\n\n\n");
System.out.println(customer + "");
System.out.println("\n\n" + " End" + "\n\n");
if(!objects.isEmpty())
{
System.out.println("\n4");
boolean exist= false;
String custToRem = null;
for(int i = 0; i< objects.size(); i++)
{
//A few prints to make sure the values are equals.
System.out.println("1\n");
System.out.println("1a\n");
System.out.println(objects.get(i).substring(0, 5));
System.out.println("1b\n");
System.out.println(customer.substring(0, 5));
System.out.println("1c\n");
if(objects.get(i).substring(0,5).equals(customer.substring(0, 5))) //&& objects.get(i).substring(1, 20).equals(customer.substring(1, 20)))
{
System.out.println("2 Deleting");
custToRem = objects.get(i);
System.out.println(custToRem);
System.out.println("3 Deleted");
exist = true;
}
else
exist = false;
}
if(exist = true)
{
System.out.println("4");
System.out.println(custToRem);
objects.remove(custToRem);
objects.add(customer);
System.out.println("5");
}
else
{
System.out.println("6");
objects.add(custToRem);
System.out.println("7");
}
System.out.println(objects.toString());
}
else
objects.add(customer);
}
//------------------------------------------------------------------------------------------------
// Description: A method that removes a value from the list Array. This by searching throughout the
// list for an identical value.
// Arguments: Long for Id customer to be remove from the list array.
// Return: None.
//------------------------------------------------------------------------------------------------
public void removeObj(long iD)
{
String obj = String.valueOf(iD);
System.out.println("remove fr GUI, iD: " + obj);
String customer = bank.infoCustomer(iD);
Iterator<String> itr = objects.iterator();
String element = "";
while(itr.hasNext())
{
element = (String) itr.next();
if(element.contains(customer))
{
itr.remove();
System.out.println("\n\nitr removed, from removeObj() -GUI ");
break;
}
}
}