Backend/java

간단한 입출금 프로그래밍을 만들어 보자 .( class Account )

IT grow. 2018. 8. 6. 22:31
반응형


package day06; // 패키지명
public class Account { //
String number; // 계좌
String name; // 이름
int money; // 잔고 변수 money , member variable
// 입금
//Static을 못쓴다 --> 왜냐하면 this를 쓰고 있기 때문이다 .
public void input(int money) // local variable(메모리 위치는 Stack에 위치한다)
{
this.money = this.money + money; // member money에 void에서 입력한 money에 값을 더하기 할 것이다.
// 만약 생략을 하면 this가 존재하는 것이다 .
// void 밖에 있는 변수 money를 사용하기 위해서 this를 쓴다.
System.out.println(number + " <= 입금 " + money);
return;
}
//Static을 못쓴다 --> 왜냐하면 this를 쓰고 있기 때문이다 .
public int output(int money) // int 변수형을 선언했기 때문에 return이 올수 있는 것이고 , 만약 void
{
if (money > this.money) {
System.out.println("잔고부족");
return 0;
}
System.out.println(number + " <= 출금 " + money);
this.money = this.money - money;
return money;
}
//Static을 못쓴다 --> 왜냐하면 this를 쓰고 있기 때문이다 . 여기서는 this를 숨기고 있다. 생략이 되어 있는 것이다 .
public void print() // 계좌정보 출력
{
System.out.printf("Account[%s : %s : %d 원]\n", name, number, this.money);
}
// 계좌이체 메소드 : transfer
public void transfer(Account from, Account to, int money)
{
System.out.println("계좌이체시작");
// to.input(from.output(money));
if (from == null || to == null || from.money < money)
{
System.out.println("Transfer Error");
return;
}
from.output(money);
to.input(money);
// to.input(from.output(money));
}
public Account find(String number) // 이 계좌에서 계좌번호를 찾아줘~
{
//~~~~
Account a = new Account();
//return a ;
return null; // 여기서 못찾았어
}
}


반응형