Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class Bangko {
- private String accountNum;
- private String accountHold;
- private double balance;
- Bangko(String accountNum, String accountHold, double balance)
- {
- this.accountHold = accountHold;
- this.accountNum = accountNum;
- this.balance = balance;
- }
- String getAccountNum()
- {
- return accountNum;
- }
- String getAccountHold()
- {
- return accountHold;
- }
- double getBalance()
- {
- return balance;
- }
- void setAccountNum(String accountNum)
- {
- this.accountNum = accountNum;
- }
- void setAccountHold(String accountHold)
- {
- this.accountHold = accountHold;
- }
- void setBalance(double balance)
- {
- if (balance < 0)
- {
- System.out.println("ERROR! Balance cannot be Nigative");
- JOptionPane.showMessageDialog(null,
- "ERROR! Balance cannot be Nigative",
- "ERROR!!", JOptionPane.ERROR_MESSAGE);
- }
- this.balance = balance;
- }
- void deposit(double amount) {
- if (amount > 0) { // whole number ba ang negative????
- balance = amount + balance;
- System.out.println("Deposit successful. New balance: " + balance);
- JOptionPane.showMessageDialog(null, "Deposit successful. New balance: " + balance);
- } else { // Negative amount
- System.out.println("Invalid! Please enter a valid amount.");
- JOptionPane.showMessageDialog(null,
- "Invalid! Try again..",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- void withdraw(double amount) {
- if (amount <= balance) { // amount less than balance, <= balance
- balance = balance - amount;
- System.out.println("Withdrawal successful. New balance: " + balance + " PHP");
- JOptionPane.showMessageDialog(null, "Withdrawal successful. New balance: " + balance + " PHP");
- } else {
- System.out.println("Insufficient balance. Maximum withdrawal allowed: " + balance + " PHP");
- JOptionPane.showMessageDialog(null,
- "Insufficient balance. Try again.. \n Maximum withdrawal allowed: " + balance + " PHP",
- "Kinapos", JOptionPane.WARNING_MESSAGE);
- }
- }
- void Display()
- {
- String OUTPUT = "Account Number: " + accountNum + "\n" +
- "Account Holder Name: " + accountHold + "\n" +
- "Balance: " + balance + " PHP";
- JOptionPane.showMessageDialog(null,OUTPUT);
- System.out.println("Account Number: " + accountNum);
- System.out.println("Account Holder Name: " + accountHold);
- System.out.printf( "Balance: %6.2f\n\n", balance);
- }
- void GUI()
- {
- JFrame frame = new JFrame("Bangko Central Ng JAVA");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JButton button1, button2, button3;
- button1 = new JButton("Deposit");
- button1.addActionListener((ActionEvent e) -> {
- System.out.println("Deposit clicked!");
- // Add desired functionality here
- double amount;
- do {
- try {
- String input = JOptionPane.showInputDialog("Deposit Amount: ");
- if (input == null) {
- System.out.println("Deposit canceled.");
- return; //
- }
- amount = Double.parseDouble(input);
- break;
- //Jump below to deposit then set its value
- } catch (NumberFormatException i ){
- JOptionPane.showMessageDialog(null, "Invalid! Please enter a valid amount.");
- }
- } while (true);
- deposit(amount);
- });
- button2 = new JButton("Withdraw");
- button2.addActionListener((ActionEvent e) -> {
- System.out.println("Withdraw clicked!");
- // Add desired functionality here
- double amount;
- do {
- try {
- String input = JOptionPane.showInputDialog("Withdraw Amount: ");
- if (input == null) {
- System.out.println("Withdraw canceled.");
- return;
- }
- amount = Double.parseDouble(input);
- break;
- //Talon sa baba tapos set Withdraw(value)
- } catch (NumberFormatException i ){
- JOptionPane.showMessageDialog(null, "Invalid! Please enter a valid amount.");
- }
- } while (true);
- withdraw(amount);
- });
- button3 = new JButton("Check Balance");
- button3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.out.println("Balance Clicked");
- Display();
- }
- });
- frame.add(button1);
- frame.add(button2);
- frame.add(button3);
- frame.setLocationRelativeTo(null);
- frame.pack();
- frame.setLayout(new FlowLayout());
- frame.setSize(400, 100);
- frame.setVisible(true);
- }
- public static void main(String[] args)
- {
- Bangko bank = new Bangko("6917412896257575","Padullon Gaudenz",9000);
- System.out.println(System.getProperty("user.dir"));
- bank.GUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement