> Java > java지도 시간 > 본문

Java의 ATM 프로그램

WBOY
풀어 주다: 2024-08-30 15:14:38
원래의
609명이 탐색했습니다.

Java로 ATM 프로그램을 구성하여 ATM 거래를 표시할 수 있습니다. 현금 자동 입출금기(ATM) 또는 현금 지급기(영국 영어)는 은행 회사의 고객이 금융 거래를 수행할 수 있도록 하는 전자 통신 시스템입니다. 사용자는 ATM 애플리케이션 화면에 표시된 옵션 중에서 선택해야 합니다. 예를 들어 출금, 입금, 잔액 확인, 사용 가능한 옵션 종료 등이 있습니다.

광고 이 카테고리에서 인기 있는 강좌 JAVA MASTERY - 전문 분야 | 78 코스 시리즈 | 15가지 모의고사

Java에서 ATM 프로그램 작업

출금하기 전에 자금을 인출하고 입금하고 계좌 잔고를 확인하려면 ATM 프로그램에서 다음 작업을 수행해야 합니다.

  • 출금: 자금 출금을 위해 사용자로부터 출금 금액을 받아 전체 잔액에서 차감한 후 메시지를 표시합니다.
  • 입금: 자금 입금을 위해 사용자로부터 추가할 입금액을 받아 전체 잔액에 추가한 후 메시지를 표시합니다.
  • 잔액 확인: 잔액 확인을 위해 사용자의 총 잔액을 표시합니다.
  • 나가기: 현재 거래 모드를 종료하여 사용자를 홈페이지 또는 초기 화면으로 되돌립니다.

Java ATM 프로그램 예시

아래는 Java로 작성된 ATM 프로그램의 예입니다.

인출 금액, 입금액, 잔액 확인을 위한 Java ATM 프로그램 예시

코드:

package jex;
import java.util.*;
class ATM {
public static void main( String args[] ) {
//declare and initialize balance, withdraw, and deposit
int balance = 50000;
int withdraw, deposit;
//create scanner class object to get choice of user
Scanner sc = new Scanner(System.in);
while(true)
{
System.out.println( "Welcome to ATM ... " );
System.out.println( "Select 1 for Withdraw" );
System.out.println( "Select 2 for Deposit" );
System.out.println( "Select 3 for Check Balance" );
System.out.println( "Select 4 for EXIT" );
System.out.print( "Select the appropriate options you want to perform:" );
//get the user selected option
int op = sc.nextInt( );
switch( op )
{
case 1: System.out.print( "Enter the amount to be withdrawn :" );
// accept the withdraw amount from the user
withdraw = sc.nextInt();
//check whether the balance is greater than or equal to the withdrawal amount
withdraw( balance, withdraw);
break;
case 2: System.out.print( "Enter the amount to be deposited :" );
//accept the deposit amount from the user
deposit = sc.nextInt();
// call the function and add the deposit amount to the total balance
deposit( balance, deposit );
break;
case 3:
// printing the total balance of the user
printBalance( balance );
System.out.println(" ");
break;
case 4:
// exit from the menu
System.exit( 0 );
}
}
}
// function to print the current balance in an account
public static void printBalance(int balance)
{
System.out.println(" The Current Balance : " + balance);
System.out.println();
}
// The function to Withdraw an amount and update the balance
public static int withdraw(int balance, int withdrawAmount)
{
System.out.println( "Withdrawn Operation :" );
System.out.println("The withdrawing Amount is : " + withdrawAmount);
if (balance >= withdrawAmount) {
balance = balance - withdrawAmount;
System.out.println( "Please collect your money and remove the card" );
printBalance( balance );
}
else {
System.out.println( "Sorry! the balanace is insufficient." );
System.out.println( );
}
return balance;
}
// The function to deposit an amount and update the balance
public static int deposit(int balance, int depositAmount)
{
System.out.println( "Deposit Operation :" );
System.out.println(" The depositing amount is : " + depositAmount);
balance = balance + depositAmount;
System.out.println( "Your Money has been successfully deposited" );
printBalance(balance);
return balance;
}
}
로그인 후 복사

출력:

위 출금 작업 코드의 출력은 다음과 같습니다.

Java의 ATM 프로그램

위 입금 작업 코드의 출력은 다음과 같습니다.

Java의 ATM 프로그램

마지막으로 입금 작업을 위한 위 코드의 출력은 다음과 같습니다.

Java의 ATM 프로그램

위 프로그램과 마찬가지로,withdrawal(),deposit(),printbalance()함수를 포함하는 ATM 클래스가 생성됩니다. 철회() 함수는 철회 작업을 수행하는 데 사용됩니다. 이 함수는 잔액과 인출 금액을 승인합니다. draw() 함수 내에서 먼저 잔액이 출금 금액보다 큰지 확인합니다. true인 경우 잔액에서 인출 금액을 빼서 잔액을 업데이트합니다. 다음으로, 예치 작업을 수행하기 위해 예금() 함수가 사용됩니다. 이 기능은 잔액과 입금액을 승인합니다.

deposit() 함수 내부에서는 잔액에 입금액을 더해 잔액을 업데이트합니다. 다음으로, printbalance() 함수는 잔액을 인쇄하는 데 사용됩니다. 균형을 받아들입니다. 그런 다음 메인 함수에서 정수의 잔액 변수가 생성됩니다. 다음으로, 위 출력에서 ​​볼 수 있듯이 케이스가 실행하게 되는 특정 옵션 선택에 따라 인출, 예금, 잔액 및 종료 작업을 위한 선택 피톤을 인쇄합니다.

결론

현금자동입출금기(ATM)는 은행권 고객이 금융거래를 할 수 있도록 해주는 전자통신 시스템입니다. Java로 ATM 프로그램을 작성하여 ATM 거래를 표시할 수 있으며, 사용자는 현금 인출, 입금, 잔액 확인 및 ATM에서 나갈 수 있습니다.

위 내용은 Java의 ATM 프로그램의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!