Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mybank;
- import javax.swing.JOptionPane; // IMPORT ALERT CLASS
- import java.util.Scanner; // SCANNER FOR READ THE USER INPUT
- import java.util.Random; // GENERATE RANDOM NUMBERS
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in); // CREATE SCANNER VAR
- Random rand = new Random(); // CREATE RAND VAR
- JOptionPane alert = new JOptionPane(); // CREATE ALERT VAR
- int amount; // MONEY FOR WITHDRAW
- int[] notes = {0, 0, 0, 0}; // NOTES ARRAY {RM100, RM50, RM20, RM10}
- int tempBalance = 0; // TEMP DATA
- int accNum = rand.nextInt(999999999); // GENERATE RANDOM NUMBER (0 - 99999999)
- while (true) {
- System.out.println("Enter the amount to withdraw: ");
- amount = scanner.nextInt();
- // ----------------------------------- RM 100
- tempBalance = (int) (amount / 100);
- notes[0] = tempBalance;
- // ----------------------------------- RM 50
- amount = amount - (notes[0] * 100);
- tempBalance = (int) (amount / 50);
- notes[1] = tempBalance;
- // ----------------------------------- RM 20
- amount = amount - (notes[1] * 50);
- tempBalance = (int) (amount / 20);
- notes[2] = tempBalance;
- // ----------------------------------- RM 10
- amount = amount - (notes[2] * 20);
- tempBalance = (int) (amount / 10);
- notes[3] = tempBalance;
- // ----------------------------------- END
- amount = amount - (notes[3] * 10);
- if(amount != 0){
- // PROBLEM ALERT
- JOptionPane.showMessageDialog(alert, "PLEASE ENTER ANOTHER AMOUNT THAT CAN BE BREAK INTO POSSIBLE BANK NOTE","WARNING",JOptionPane.ERROR_MESSAGE);
- }else{
- break; // STOP LOOP
- }
- }
- // RECEIPT
- System.out.println("ACC NO: " + accNum); // ? RANDOM ACCOUNT NUMBER !UNIMPORTANT
- System.out.println("\nCASH WITHDRAWAL:");
- System.out.println("RM 10 X " + notes[3] + " =\t\t" + (notes[3] * 10));
- System.out.println("RM 20 X " + notes[2] + " =\t\t" + (notes[2] * 20));
- System.out.println("RM 50 X " + notes[1] + " =\t\t" + (notes[1] * 50));
- System.out.println("RM 100 X " + notes[0] + " =\t\t" + (notes[0] * 100));
- 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)));
- System.out.println("\nTRANSACTION ACCEPTED");
- System.out.println("\nRESPONSE CODE: 000\t ACCEPTED");
- System.out.println("\nTHANK YOU FOR BANKING WITH US");
- }
- }
- # OUTPUT
- https://easytoviral.com/mybank/output.png
Advertisement
Add Comment
Please, Sign In to add comment