amlxv

yoyo

Apr 11th, 2020 (edited)
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.85 KB | None | 0 0
  1. package com.mybank;
  2. import javax.swing.JOptionPane; // IMPORT ALERT CLASS
  3. import java.util.Scanner; // SCANNER FOR READ THE USER INPUT
  4. import java.util.Random; // GENERATE RANDOM NUMBERS
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in); // CREATE SCANNER VAR
  9.         Random rand = new Random(); // CREATE RAND VAR
  10.         JOptionPane alert = new JOptionPane(); // CREATE ALERT VAR
  11.         int amount; // MONEY FOR WITHDRAW
  12.         int[] notes = {0, 0, 0, 0}; // NOTES ARRAY {RM100, RM50, RM20, RM10}
  13.         int tempBalance = 0; // TEMP DATA
  14.         int accNum = rand.nextInt(999999999); // GENERATE RANDOM NUMBER (0 - 99999999)
  15.         while (true) {
  16.             System.out.println("Enter the amount to withdraw: ");
  17.             amount = scanner.nextInt();
  18.             // ----------------------------------- RM 100
  19.             tempBalance = (int) (amount / 100);
  20.             notes[0] = tempBalance;
  21.             // ----------------------------------- RM 50
  22.             amount = amount - (notes[0] * 100);
  23.             tempBalance = (int) (amount / 50);
  24.             notes[1] = tempBalance;
  25.             // ----------------------------------- RM 20
  26.             amount = amount - (notes[1] * 50);
  27.             tempBalance = (int) (amount / 20);
  28.             notes[2] = tempBalance;
  29.             // ----------------------------------- RM 10
  30.             amount = amount - (notes[2] * 20);
  31.             tempBalance = (int) (amount / 10);
  32.             notes[3] = tempBalance;
  33.             // -----------------------------------  END
  34.             amount = amount - (notes[3] * 10);
  35.             if(amount != 0){
  36.                 // PROBLEM ALERT
  37.                 JOptionPane.showMessageDialog(alert, "PLEASE ENTER ANOTHER AMOUNT THAT CAN BE BREAK INTO POSSIBLE BANK NOTE","WARNING",JOptionPane.ERROR_MESSAGE);
  38.             }else{
  39.                 break; // STOP LOOP
  40.             }
  41.         }
  42.         // RECEIPT
  43.         System.out.println("ACC NO: " + accNum); // ? RANDOM ACCOUNT NUMBER !UNIMPORTANT
  44.         System.out.println("\nCASH WITHDRAWAL:");
  45.         System.out.println("RM 10   X   "  + notes[3] + " =\t\t" + (notes[3] * 10));
  46.         System.out.println("RM 20   X   "  + notes[2] + " =\t\t" + (notes[2] * 20));
  47.         System.out.println("RM 50   X   "  + notes[1] + " =\t\t" + (notes[1] * 50));
  48.         System.out.println("RM 100  X   "  + notes[0] + " =\t\t" + (notes[0] * 100));
  49.         System.out.println("TOTAL   =   " + (notes[3]+notes[2]+notes[1]+notes[0]) + " = \tRM" + ((notes[3] * 10)+(notes[2] * 20)+(notes[1] * 50)+(notes[0] * 100)));
  50.         System.out.println("\nTRANSACTION ACCEPTED");
  51.         System.out.println("\nRESPONSE CODE: 000\t ACCEPTED");
  52.         System.out.println("\nTHANK YOU FOR BANKING WITH US");
  53.     }
  54. }
  55.  
  56.  
  57. # OUTPUT                                   
  58. https://easytoviral.com/mybank/output.png
Advertisement
Add Comment
Please, Sign In to add comment