Advertisement
Gaudenz

Bangko

Feb 21st, 2024 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.68 KB | Source Code | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. class Bangko {
  6.    
  7.     private String accountNum;
  8.     private String accountHold;
  9.     private double balance;
  10.    
  11.     Bangko(String accountNum, String accountHold, double balance)
  12.     {
  13.         this.accountHold = accountHold;
  14.         this.accountNum = accountNum;
  15.         this.balance = balance;
  16.     }
  17.    
  18.     String getAccountNum()
  19.     {
  20.     return accountNum;
  21.     }
  22.    
  23.     String getAccountHold()
  24.     {
  25.      return accountHold;
  26.     }
  27.    
  28.     double getBalance()
  29.     {
  30.      return balance;
  31.     }
  32.    
  33.     void setAccountNum(String accountNum)
  34.     {
  35.         this.accountNum = accountNum;
  36.     }
  37.     void setAccountHold(String accountHold)
  38.     {
  39.         this.accountHold = accountHold;
  40.     }
  41.     void setBalance(double balance)
  42.     {
  43.         if (balance < 0)
  44.         {
  45.         System.out.println("ERROR! Balance cannot be Nigative");
  46.         JOptionPane.showMessageDialog(null,
  47.                 "ERROR! Balance cannot be Nigative",
  48.                 "ERROR!!", JOptionPane.ERROR_MESSAGE);
  49.         }
  50.         this.balance = balance;
  51.     }
  52.  
  53.     void deposit(double amount) {
  54.  
  55.     if (amount > 0) { // whole number ba ang negative????
  56.         balance = amount + balance;
  57.         System.out.println("Deposit successful. New balance: " + balance);
  58.         JOptionPane.showMessageDialog(null, "Deposit successful. New balance: " + balance);
  59.    
  60.        
  61.     } else { // Negative amount
  62.         System.out.println("Invalid! Please enter a valid amount.");
  63.         JOptionPane.showMessageDialog(null,
  64.                 "Invalid! Try again..",
  65.                 "Error", JOptionPane.ERROR_MESSAGE);
  66.      
  67.     }
  68. }
  69.  
  70. void withdraw(double amount) {
  71.  
  72.     if (amount <= balance) { // amount less than balance,  <= balance
  73.         balance = balance - amount;
  74.  
  75.         System.out.println("Withdrawal successful. New balance: " + balance + " PHP");
  76.         JOptionPane.showMessageDialog(null, "Withdrawal successful. New balance: " + balance + " PHP");
  77.      
  78.     } else {
  79.         System.out.println("Insufficient balance. Maximum withdrawal allowed: " + balance + " PHP");
  80.         JOptionPane.showMessageDialog(null,
  81.                 "Insufficient balance. Try again.. \n Maximum withdrawal allowed: " + balance + " PHP",
  82.                 "Kinapos", JOptionPane.WARNING_MESSAGE);
  83.     }
  84. }
  85.  
  86.     void Display()
  87.     {
  88.         String OUTPUT = "Account Number:  " + accountNum + "\n" +
  89.                         "Account Holder Name:  " + accountHold + "\n" +
  90.                         "Balance: " + balance + " PHP";
  91.        
  92.         JOptionPane.showMessageDialog(null,OUTPUT);
  93.        
  94.         System.out.println("Account Number: " + accountNum);
  95.         System.out.println("Account Holder Name: " + accountHold);
  96.         System.out.printf( "Balance: %6.2f\n\n", balance);
  97.     }
  98.    
  99.   void GUI()
  100.  {
  101.         JFrame frame = new JFrame("Bangko Central Ng JAVA");
  102.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  103.         JButton button1, button2, button3;
  104.        
  105.         button1 = new JButton("Deposit");
  106.         button1.addActionListener((ActionEvent e) -> {
  107.             System.out.println("Deposit clicked!");
  108.             // Add desired functionality here
  109.             double amount;
  110.             do {
  111.                 try {
  112.                  String input = JOptionPane.showInputDialog("Deposit Amount: ");
  113.                  if (input == null) {
  114.                     System.out.println("Deposit canceled.");
  115.                     return; //
  116.                 }
  117.                  
  118.                 amount = Double.parseDouble(input);
  119.                 break;
  120.                 //Jump below to deposit then set its value
  121.                
  122.                 } catch (NumberFormatException i ){
  123.               JOptionPane.showMessageDialog(null, "Invalid! Please enter a valid amount.");
  124.              }
  125.             } while (true);
  126.            
  127.             deposit(amount);            
  128.         });
  129.  
  130.          button2 = new JButton("Withdraw");
  131.         button2.addActionListener((ActionEvent e) -> {
  132.             System.out.println("Withdraw clicked!");
  133.             // Add desired functionality here
  134.             double amount;
  135.             do {
  136.                 try {
  137.                  String input = JOptionPane.showInputDialog("Withdraw Amount: ");
  138.                     if (input == null) {
  139.                     System.out.println("Withdraw canceled.");
  140.                     return;
  141.                 }
  142.                 amount = Double.parseDouble(input);
  143.                
  144.              
  145.                 break;
  146.                 //Talon sa baba tapos set Withdraw(value)
  147.                
  148.                 } catch (NumberFormatException i ){
  149.               JOptionPane.showMessageDialog(null, "Invalid! Please enter a valid amount.");
  150.              }
  151.             } while (true);
  152.            
  153.             withdraw(amount);
  154.         });
  155.        
  156.          button3 = new JButton("Check Balance");
  157.         button3.addActionListener(new ActionListener() {
  158.             public void actionPerformed(ActionEvent e) {
  159.                 System.out.println("Balance Clicked");
  160.                 Display();
  161.             }
  162.         });
  163.        
  164.         frame.add(button1);
  165.         frame.add(button2);
  166.         frame.add(button3);
  167.      
  168.         frame.setLocationRelativeTo(null);
  169.         frame.pack();
  170.         frame.setLayout(new FlowLayout());
  171.         frame.setSize(400, 100);
  172.         frame.setVisible(true);
  173.  }
  174.    
  175.     public static void main(String[] args)
  176.     {
  177.     Bangko bank = new Bangko("6917412896257575","Padullon Gaudenz",9000);
  178.    System.out.println(System.getProperty("user.dir"));
  179.  
  180.     bank.GUI();
  181.     }
  182.    
  183. }
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement