Wenn ich den Kontostand eines bestimmten Datensatzes im Array unter Verwendung der Ein- und Auszahlungsbeträge aktualisiere, ändert sich der Saldo für diesen bestimmten Datensatz zusammen mit dem Saldo für die Datensätze in Arrays.Wert in mehreren Feldern angepasst
Wie es zu beheben?
private String name;
private int pin;
private int account;
private static double balance;
public void setBalance(double amount)
{
balance = amount;
}
public static void deposit(double aDeposit)
{
balance = balance + aDeposit;
}
public static void withdraw(double aWithdraw)
{
if
(balance >= aWithdraw)
balance = balance - aWithdraw;
else if
(balance < aWithdraw)
System.out.println("Cannot withdarw amount.");
}
public double getBalance()
{
return balance;
}
public boolean equal(CustomerRecord otherObject)
{
return (name.equalsIgnoreCase(otherObject.name) &&
(pin == otherObject.pin) &&
(account == otherObject.account) &&
(balance == otherObject.balance));
}
}
do{
System.out.println("Enter the name");
String aName;
Scanner keyboard = new Scanner(System.in);
aName = keyboard.nextLine();
System.out.println("Enter the pin");
int aPin;
aPin = keyboard.nextInt();
for
(int i = 0; i < index; i++) {
CustomerRecord record = anotherArray[i];
if
((record.getName().equalsIgnoreCase(aName)) && (record.getPin() == (aPin)))
{
System.out.println(record);
System.out.println("Enter the amount you wish to Deposit");
double aDeposit;
aDeposit = keyboard.nextDouble();
CustomerRecord.deposit(aDeposit);
System.out.println("Enter the amount you wish to withdraw");
double aWithdraw;
aWithdraw = keyboard.nextDouble();
CustomerRecord.withdraw(aWithdraw);
record.getBalance();
}
}
System.out.println("\nAnother Transaction? (y for yes) (n for no)");
repeat = keyboard.next().charAt(0);
}
while
(
repeat == 'y' || repeat == 'Y') ;
//Print the records on screen
{ for (int i = 0; i < index; i++)
System.out.print(anotherArray[i]);
}
Okay, ich habe Ihnen gezeigt, wie ich meine Variablen definiert. Was bedeutet Statik? – Jake
Also ist es * statisch. Das ist nicht überraschend. Was bedeutet es für ein "Feld", "statisch" zu sein? –
haha! Brillant. Vielen Dank! – Jake