كيفاش تصاوب تطبيق بنك بالJava

imadbelasri Java
JA

فهاد الدرس من كيفاش تصاوب تطبيق بنك بال Java غادي نصاوبو واحد التطبيق لي كيمكن المستخدم من إجراء معاملات بنكية وضع نقود فالحساب سحب مبالغ و عمليات أخرى التطبيق بسيط للمبتدئين.


نظرة سريعة بالفيديو


- الملف Operation.java

كتمشي ل IDE لي كتخدم بها انا خدمت ب NETBEANS من بعد كتزيد مشروع جديد سميه bankapp من بعد زيد فيه ملف جديد عبارة عن class سميها Operation.java فيها غادي يكون الكود لي غادي يتضمن جميع المعاملات غادي نقسمو على جوج فهاد الجزء كاين fonction Versement لي كتزيد مبلغ فالحساب فهي كتخد المبلغ وكتزيدو للصولد لقديم ثم fonction Retrait لي كتنقص المبلغ لي قرر المستخدم يسحبو من الصولد وكتسجل العملية كعملية سابقة ثمfonction operationsPrecedentes لي فقط كتعرض العملية السابقة واش سحب ولا إضافة الكود هو :

                                                    
                                                        /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bankapp;

import java.util.Scanner;
import static javafx.application.Platform.exit;

/**
 *
 * @author Imad
 */
public class Operation implements CreateMenu{
    int solde;
    int operationPrec;
    String nom;
    String client_id;
    public Operation(String cname,String c_id){
        this.nom = cname;
        this.client_id = c_id;
    }
    public void Versement(int amount){
        if(amount != 0){
            solde = solde + amount;
            operationPrec = amount;
        }
    }
    public void Retrait(int amount){
        if(amount != 0){
            solde = solde - amount;
            operationPrec = -amount;
        }
    }
    public void operationsPrecedentes(){
        if(operationPrec > 0){
            System.out.println("Versement montant : "+ operationPrec);
        }else if(operationPrec < 0){
            System.out.println("Retrait montant : "+ Math.abs(operationPrec));
        }else{
            System.out.println("Aucune opération");
        }
    }

                                                    
                                                

- الملف Operation.java تتمة

فهاد الجزء الثاني من الملف Operation.java كنزيد واحد ل fonction showMenu ولي كتعرض الإسم ولid ديال المستخدم من بعد كتقول للمستخدم يختار حرف من القائمة المعروضة منبعد مكتسترجع الحرف لي دخل المستخدم كتحقق منوكان A كتعرض الصولد ديال المستخدم كان B كتقولو دخل المبلغ لي باغي تزيد كان c كتقولو دخل المبلغ لي باغي تسحب كان D كتعرض العمليات السابقة كان E كتغلق التطبيق وتعرض رسالة شكر الكود ديال الملف هو :

                                                        
                                                                @Override
    public void showMenu() {
        char option = 'o';
        Scanner scanner = new Scanner(System.in);
        System.out.println("Bienvenue :"+ nom);
        System.out.println("Votre id :"+ client_id);
        System.out.println("\n");
        System.out.println("A.Consulter votre solde");
        System.out.println("B.Versement");
        System.out.println("C.Retrait");
        System.out.println("D.Opération precédente");
        System.out.println("E.Sortir");
        do{
            System.out.println("================================================================");
            System.out.println("Veuillez choisir une option");
            System.out.println("================================================================");
            option = scanner.next().charAt(0);
            switch(option){
                case 'A' :
                    System.out.println("===============================");
                    System.out.println("Votre solde :"+ solde);
                    System.out.println("===============================");
                    System.out.println("\n");
                break;
                case 'B' :
                System.out.println("===============================");
                    System.out.println("Entrer le montant à verser :");
                    int amount = scanner.nextInt();
                    Versement(amount);
                    System.out.println("\n");
                break;
                case 'C' :
                System.out.println("===============================");
                    System.out.println("Entrer le montant à retirer :");
                    int amt = scanner.nextInt();
                    Retrait(amt);
                    System.out.println("\n");
                break;
                case 'D' :
                    System.out.println("===============================");
                    operationsPrecedentes();
                    System.out.println("==============================="); 
                    System.out.println("\n");
                break;
                case 'E' :
                    System.out.println("==============================="); 
                break;
                default:
                    System.out.println("Opération invalide!"); 
                break;
            }
        }while(option != 'E');
        System.out.println("Merci pour votre visite."); 
    }
    
}
                                                        
                                                    

- الملف CreateMenu.java

فالمجلد ديال المشروع ديالنا زيد ملف جديد سميه CreateMenu.java ولي عبارة عن interface فيها fonction showMenu لي هي لي كي executer الملف Operation.java الكود ديال الملف هو :

                                                        
                                                            /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bankapp;

/**
 *
 * @author Imad
 */
public interface CreateMenu {
    public void showMenu();
}
                                                        
                                                    

- الملف BankApp.java

هادا هو الملف الرئيسي ديالنا ولي كي créer l'objet مل class Operation وكيعطيه سمية المستخدم ول id ديالو من بعد كيعرض القائمة بواسطة ل fonction showMenu الكود ديالو هو :

                                                        
                                                            /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bankapp;

/**
 *
 * @author Imad
 */
public class BankApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Operation operation = new Operation("Belasri","12");
       operation.showMenu();
    }
    
}