1
입금액과 인출 금액을 사용하여 배열의 특정 레코드의 잔액을 업데이트하면 해당 레코드의 잔액이 배열의 레코드 잔액과 함께 변경됩니다.값이 여러 배열로 조정됨
문제를 해결하는 방법은 무엇입니까?
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));
}
}
당신이
balance
필드를 정의하지만, 당신이
static
방법
deposit
및
withdraw
I에서 액세스 할 수 있다는 사실에가는 당신은 표시하지 않은
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]);
}
좋아요, 변수를 어떻게 정의했는지 보여 줬습니다. 정적은 무엇을 의미합니까? – Jake
그래서 * 정적 *입니다. 놀라운 일은 아닙니다. '필드'가 '정적'이라는 것은 무엇을 의미합니까? –
하하! 훌륭한. 정말 고마워! – Jake