일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 객체
- xss game
- 파이썬
- github
- 포인터
- 사칙연산
- element 조회
- 메소드
- blind sql injection
- property
- 자바스크립트
- document
- 조건문
- lord of sql injection
- Pwndbg
- suninatas 풀이
- 백준 파이썬
- jQuery
- htmlspecialchars
- burp suite
- object
- 백준 알고리즘
- IF문
- sql injection
- 김성엽 대표님
- 함수
- window
- 배열
- xss game 풀이
- python
Archives
- Today
- Total
power-girl0-0
간단한 Bank 프로그램 구현하기 본문
728x90
안녕하세요-!!
오랜만에 돌아왔어요ㅠㅠ
오늘은 간단한 은행업무에 대해서 써볼까~?? 합니다.
저희가 오늘 같이 구현할 친구는 해당 사용자의 번호 입력에 따라 다른 기능이 수행되는 것을 구현해 볼 것입니다-!!
import java.util.Scanner; //scanner을 사용하기 위해 선언
class Bank{
String name; //이름
int pwd; //비밀번호
int input, output; //input은 입금 , output은 출금
int balance=0; //잔액을 0으로 초기화
public Bank(String name, int pwd, int balance) { //회원 정보를 받아오는 메소드
this.name = name;
this.pwd = pwd;
this.balance = balance;
}
public void my() {
System.out.println("회원 정보 [이름 :" + this.name + ", 비밀번호 :" + this.pwd +", 잔액 :" + balance+"]\n");
}
public void setInput(int input){ //입금 메소드
this.balance += input;
System.out.println("입금 후 잔액조회 : "+this.balance);
}
public void setOutput(int output){ //출금 메소드
this.balance -= output;
System.out.println("출금 후 잔액조회 : "+this.balance);
}
public void getBalance(){ //잔액조회 메소드
System.out.println("잔액조회 : " + balance);
}
}
public class BankMain {
public static void main(String[] args) {
Bank b = new Bank("홍길동", 1234, 12500); //회원 정보를 받아 Bank()메소드에 전달해줌
System.out.println("원하는 서비스를 입력해주세요.\n");
b.my(); //Bank클래스의 my()메소드에서 회원정보를 가져와 출력
while(true) //무한 반복문
{
System.out.println("1. 입금 2. 출금 3. 잔액조회");
Scanner sc=new Scanner(System.in); //사용자에게 입력받기 위해 sc로 변수 선언
int choose = sc.nextInt(); //사용자에게 입력받은 값을 choose에 저장
switch(choose) //choose의 값을 조건으로 해당 번호의 기능을 실행시킴
{
case 1 :
System.out.print("입금액 ? : ");
b.setInput(sc.nextInt()); //입력받은 입금값을 setInput 메소드를 바탕으로 출력해줌
break;
case 2 :
System.out.print("출력액 ? : ");
b.setOutput(sc.nextInt()); //입력받은 출금값을 setOutput 메소드를 바탕으로 출력해줌
break;
case 3 :
b.getBalance(); //잔액조회 메소드 출력
break;
default : //1,2,3번 외의 숫자를 입력시 실행됨
System.out.println("올바른 숫자를 입력해주세요");
}
}
}
}
다음 소스의 결과값입니다-!!
끄읕~~!!! (๑•̀ㅂ•́)و✧
다들 성공적으로 끝내셨나요?ㅎㅎ
그럼 오늘 하루도 성공하신 인생을 사신 겁니다 ㅎㅎ
다음에는 더 즐거운 지식들을 들고 달려올게요~~
그때까지 안뇨옹~~ o(^▽^) o
728x90
'언어 > Java' 카테고리의 다른 글
추상클래스와 인터페이스 (0) | 2020.04.16 |
---|---|
interface를 이용하여 TV프로그램짜기 (0) | 2020.04.16 |
입력받은 값 중 가장 큰 수 출력하기 (0) | 2020.03.31 |
입력값을 받아 구구단 출력 (0) | 2020.03.31 |
구구단 짜기 (0) | 2020.03.31 |
Comments