Notice
Recent Posts
Link
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Python
- 한글깨짐해결
- dji tello
- docker container
- ubuntu에서 docker 사용
- 오목앱 만들기
- 360게임 만들기 with c
- pill ai
- AI
- C
- deep learning
- ubuntu
- 긍부정문 판별
- iris dataset
- 오목게임앱
- 춤 유사도 평가
- 시저암호 코딩
- ceasor
- docker in ubuntu
- token check
- drone control
- yolo mask
- 369게임 만들기
- Java
- aws code pipeline
- Container
- docker
- flower classification
- pill classification
- mask image training
Archives
- Today
- Total
월레스와 그로밋: 코딩의 날
Bank Account(간단한 계좌 관리) 본문
import java.util.Scanner;
abstract class HBank{
private String name;
private int accountNumber;
protected int currentBalance;
protected String Grade;
abstract void infoInquiry();
public String getName() {
return name;
}
public int getAccountNumber() {
return accountNumber;
}
HBank(String name, int accountNumber, int currentBalance, String Grade){
this.name = name;
this.accountNumber = accountNumber;
this.currentBalance = currentBalance;
this.Grade = Grade;
}
}
class DepositWithdrawalDetails extends HBank{
private double interestRate;
public double getInterestRate() {
return interestRate;
}
public void setInterestRate() {
if(Grade.equals("골드")) {
this.interestRate = 3.3;
}
else if(Grade.equals("일반"))
this.interestRate = 3.5;
}
public void infoInquiry() {
setInterestRate();
System.out.println("계좌번호 : " + getAccountNumber() + "\n이름 : " + getName() + "\n등급 : " + Grade + "\n이율 : "
+ getInterestRate() + "%");
}
void balanceInquiry() {
System.out.println(getName() + "의 현재 잔액은 "+ currentBalance);
}
void deposit(int money) {
currentBalance += money;
}
void widthdraw(int money) {
currentBalance -= money;
}
DepositWithdrawalDetails(String name, int accountNumber, int currentBalance, String Grade){
super(name, accountNumber, currentBalance, Grade);
}
}
public class BankMain {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// DepositWithdrawalDetails h[] = new DepositWithdrawalDetails[2];
HBank h[] = new DepositWithdrawalDetails[2];
h[0] = new DepositWithdrawalDetails("홍길동", 100, 12500, "골드");
h[1] = new DepositWithdrawalDetails("이순신", 200, 10000, "일반");
boolean power = true;
while(power) {
System.out.print("계좌번호를 입력 >> ");
int num1 = sc.nextInt();
for(int i=0; i<2; i++) {
if(h[i].getAccountNumber() == num1) {
DepositWithdrawalDetails d = (DepositWithdrawalDetails)h[i];
System.out.print("1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> ");
int num2 = sc.nextInt();
switch(num2) {
case 1:
System.out.print("입금할 금액 >> ");
// h[i].deposit(sc.nextInt());
d.deposit(sc.nextInt());
break;
case 2:
System.out.print("출금할 금액 >> ");
// h[i].widthdraw(sc.nextInt());
int m = sc.nextInt();
if(d.currentBalance - m < 0)
System.out.println("잔액이 부족합니다.");
else
d.widthdraw(m);
break;
case 3:
// h[i].balanceInquiry();
d.balanceInquiry();
break;
case 4:
h[i].infoInquiry();
break;
case 5:
power = false;
System.out.println("종료합니다.");
break;
}
}
}
}
sc.close();
}
}
output
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 4
계좌번호 : 100
이름 : 홍길동
등급 : 골드
이율 : 3.3%
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 3
홍길동의 현재 잔액은 12500
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 1
입금할 금액 >> 15000
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 3
홍길동의 현재 잔액은 27500
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 2
출금할 금액 >> 2000
계좌번호를 입력 >> 100
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 3
홍길동의 현재 잔액은 25500
계좌번호를 입력 >> 200
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 4
계좌번호 : 200
이름 : 이순신
등급 : 일반
이율 : 3.5%
계좌번호를 입력 >> 200
1:입금 2:출금 3:잔액조회 4:정보조회 5:종료>> 5
종료합니다.
'Etc > Java' 카테고리의 다른 글
오목게임 앱 제작(Android Studio HedgeHog) (0) | 2025.02.06 |
---|---|
Ceasor Code(시저 암호_해독 퀴즈) (1) | 2025.01.26 |