// 메소드
public class Account {
private String accountNumber; //계좌번호
private String owner; //계좌 소유주
private long balance; //잔액
//생성자
public Account(String accountNumber, String owner) {
this.accountNumber = accountNumber;
this.owner = owner;
balance = 0L;
}
public Account() {
this.accountNumber = null;
this.owner = null;
balance = 0L;
}
//입금함
public void deposit(int money) {
balance += money;
}
//출금함
//반환값 : 정상(0), 실패(-1)
public int withdraw(int money) {
if(balance >= money) {
balance -= money;
return 0;
}
return -1;
}
//계좌정보 출력
public void print() {
System.out.println("계좌번호 : " + accountNumber);
System.out.println("고객명 : " + owner + "님");
System.out.println("잔액 : " + balance +"원");
}
public void setAccountNumber(String accountNumber) { //셋터
this.accountNumber = accountNumber;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getAccountNumber() { //겟터
return this.accountNumber;
}
public String getOwner() {
return this.owner;
}
}
//메인 함수
import java.util.Scanner;
public class Accounttest {
public static void main(String[] args) {
//필요한 변수
int balanceMoney = 0;
int withdrawMoney = 0;
int n;
Account account = new Account();
boolean loop_flag = true;
Scanner sc = new Scanner(System.in);
do {
System.out.println("");
System.out.println("1)계좌번호 설정");
System.out.println("2)고객명 설정");
System.out.println("3)입금");
System.out.println("4)출금");
System.out.println("5)계좌정보 출력");
System.out.println("6)종료");
System.out.print("입력 : ");
n = sc.nextInt();
switch(n) {
case 1 : {
System.out.print("계좌번호 : ");
String accountNo = sc.next();
account.setAccountNumber(accountNo);
break;
}
case 2 : {
System.out.print("고객명 : ");
String ownerName = sc.next();
account.setOwner(ownerName);
break;
}
case 3 : {
System.out.print("입금액 : ");
balanceMoney = sc.nextInt();
account.deposit(balanceMoney);
break;
}
case 4 :{
System.out.print("출금액 : ");
withdrawMoney = sc.nextInt();
if(account.withdraw(withdrawMoney) == 0) {
System.out.println("출금성공");
}
else {
System.out.println("잔액부족");
}
break;
}
case 5 : {
account.print();
break;
}
case 6 : {
System.out.println("종료하였습니다.");
loop_flag = false;
break;
}
default : System.out.println("잘못입력 하셨습니다.");
}
} while (loop_flag == true);
sc.close();
}
}
public class Accounttest {
public static void main(String[] args) {
//필요한 변수
int balanceMoney = 0;
int withdrawMoney = 0;
int n;
Account account = new Account();
boolean loop_flag = true;
Scanner sc = new Scanner(System.in);
do {
System.out.println("");
System.out.println("1)계좌번호 설정");
System.out.println("2)고객명 설정");
System.out.println("3)입금");
System.out.println("4)출금");
System.out.println("5)계좌정보 출력");
System.out.println("6)종료");
System.out.print("입력 : ");
n = sc.nextInt();
switch(n) {
case 1 : {
System.out.print("계좌번호 : ");
String accountNo = sc.next();
account.setAccountNumber(accountNo);
break;
}
case 2 : {
System.out.print("고객명 : ");
String ownerName = sc.next();
account.setOwner(ownerName);
break;
}
case 3 : {
System.out.print("입금액 : ");
balanceMoney = sc.nextInt();
account.deposit(balanceMoney);
break;
}
case 4 :{
System.out.print("출금액 : ");
withdrawMoney = sc.nextInt();
if(account.withdraw(withdrawMoney) == 0) {
System.out.println("출금성공");
}
else {
System.out.println("잔액부족");
}
break;
}
case 5 : {
account.print();
break;
}
case 6 : {
System.out.println("종료하였습니다.");
loop_flag = false;
break;
}
default : System.out.println("잘못입력 하셨습니다.");
}
} while (loop_flag == true);
sc.close();
}
}
0 개의 댓글:
댓글 쓰기