본문 바로가기

Projects/Toy Project

Java Banking application 자바 뱅킹 어플리케이션 프로젝트

반응형

 

import java.util.Scanner;

public class ScannerTest {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter a number");
		int a = sc.nextInt();
		
		System.out.println("value = " + a);
		
	}

}

 

 

import java.util.Scanner;

public class ScannerTest {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter a Character");
	//	int a = sc.nextInt();
		
		// 문자열의 첫번째 인덱스를 가져온다는 뜻이다.
		char c = sc.next().charAt(0);
		System.out.println(c);
	}

}

---------------------------

import java.util.Scanner;

public class BankingApplication {

	public static void main(String[] args) {
		
		BankAccount obj1 = new BankAccount("XYZ", "BA0001");
		obj1.showMenu();
	}

}


class BankAccount {
	int balance;
	int previousTransaction;
	String customerName;
	String customerId;
	
	BankAccount(String cname,String cid){
		customerName = cname;
		customerId = cid;
	}
	
	void deposit(int amount) {
		if(amount > 0) {
			balance += amount;
			previousTransaction = amount;
		}
	}
	
	void withdraw(int amount) {
		if(amount > 0) {
			balance -= amount;
			previousTransaction = -amount;
		}
		
	}
	
	void getPreviousTransaction() {
		if(previousTransaction > 0) {
			System.out.println("Deposited: "+previousTransaction);
		}
		else if(previousTransaction < 0) {
			System.out.println("Withdrawn: "+Math.abs(previousTransaction));
		}
		else {
			System.out.println("No transaction occured");
		}
	}
	void showMenu() {
		char option='\0'; // char initialization
		Scanner scanner = new Scanner(System.in);
	
		System.out.println("Welcome " +customerName);
		System.out.println("Your ID is "+customerId);
		System.out.println("\n");
		System.out.println("A, Check Balance");
		System.out.println("B, Deposit");
		System.out.println("C, Withdraw");
		System.out.println("D, Previous transaction");
		System.out.println("E, Exit");
	
		do {
			System.out.println("=========================================================");
			System.out.println("Enter an option");
			System.out.println("=========================================================");
	
			option = scanner.next().charAt(0);
			System.out.println("\n");
			
			switch(option) {
			
			case 'A':
				System.out.println("-------------------------");
				System.out.println("Balance = "+balance);
				System.out.println("-------------------------");
				System.out.println("\n");
				break;
				
			case 'B':
				System.out.println("-------------------------");
				System.out.println("Enter an amount to deposit:");
				System.out.println("-------------------------");
				int amount = scanner.nextInt();
				deposit(amount);
				System.out.println("\n");
				break;
				
			case 'C':
				System.out.println("-------------------------");
				System.out.println("Enter an amount to withdraw:");
				System.out.println("-------------------------");
				int amount2 = scanner.nextInt();
				withdraw(amount2);
				System.out.println("\n");
				break;
				
			case 'D':
				System.out.println("-------------------------");
				getPreviousTransaction();
				System.out.println("-------------------------");
				System.out.println("\n");
				break;
				
			case 'E':
				System.out.println("****************************************");
				break;
				
			default:
				System.out.println("Invalid Option! Please enter again");
				break;
			}
		}
		
		while(option != 'E');
		System.out.println("Thank You for using our services");
	}
}

 

반응형

'Projects > Toy Project' 카테고리의 다른 글

주어진 숫자의 각 자리수 더하기 자바  (0) 2022.03.22
자바로 텍스트 게임 만들기  (0) 2022.02.01