Java での ATM プログラム

WBOY
リリース: 2024-08-30 15:14:38
オリジナル
609 人が閲覧しました

Java で ATM プログラムを構築して、ATM トランザクションを表示できます。現金自動預け払い機 (ATM) または現金自動預け払い機 (イギリス英語) は、銀行会社の顧客が金融取引を行うことを可能にする電子通信システムです。ユーザーは、ATM アプリケーションの画面に表示されるオプションから選択肢を選択する必要があります。たとえば、お金の引き出し、入金、残高の確認、利用可能なオプションの終了などです。

広告 このカテゴリーの人気コース JAVA マスタリー - スペシャライゼーション | 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 プログラム

上記のプログラムと同様に、withdraw()、deposit()、printbalance() 関数を含む ATM クラスが作成されます。 draw()関数は、引き出し操作を実行するために使用されます。この関数は残高と引き出し金額を受け取ります。 draw()関数内で、まず残高が出金額より大きいかどうかを確認します。 true の場合は、残高から出金額を差し引いて残高を更新します。次に、関数deposit()を使用してデポジット操作を実行します。この関数は残高と入金額を受け入れます。

deposit() 関数内で、入金額を残高に追加して残高を更新します。次に、printbalance() 関数を使用して残高を出力します。残高を受け入れます。次に、main関数内で整数のバランス変数を作成します。次に、上記の出力でわかるように、ケースで実行される特定のオプションの選択に応じて、出金、入金、残高、および終了操作の選択ピトンを出力します。

結論

現金自動預け払い機 (ATM) は、銀行会社の顧客が金融取引を行うことを可能にする電子通信システムです。 Java で ATM プログラムを作成して ATM 取引を表示し、ユーザーはお金の引き出し、入金、残高の確認、ATM からの終了を行うことができます。

以上がJava での ATM プログラムの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!