Untitled
unknown
plain_text
5 months ago
11 kB
5
Indexable
import java.util.Scanner; public class ATM_sim { public static void main(String[] args) { Scanner input = new Scanner(System.in); String account_1_name = "User_1" ; double account_1_balance = 75000; int account_1_ID = 5511; String account_2_name = "User_2" ; double account_2_balance = 15000; int account_2_ID = 4314; String account_3_name = "User_3" ; double account_3_balance = 30000; int account_3_ID = 6752; double total_profit = 0; int total_deposit = 0, total_withdraw = 0, total_transfer = 0; while(true) { System.out.println("\n********** Welcome to our Bank **********\n"); System.out.println("1- "+ "(" + account_1_ID + ") " + account_1_name ); System.out.println("2- "+ "(" + account_2_ID + ") " + account_2_name ); System.out.println("3- " + "(" + account_3_ID + ") " + account_3_name); System.out.println("4- Administrator"); System.out.println("5- Exit"); System.out.print("\nPlease choose a valid number : "); int choice = input.nextInt(); String name =""; double balance = 0; if(choice == 1) { name = account_1_name; balance = account_1_balance; } else if (choice == 2) { name = account_2_name; balance = account_2_balance; } else if (choice == 3) { name = account_3_name; balance = account_3_balance; } if(choice >= 1 && choice <= 3) { int deposit = 0, withdraw = 0 , transfer = 0; double money_in = 0 , money_out = 0; while(true) { System.out.println("\nAccount Operations Menu ," + name +" what do you need : \n"); System.out.println("1- View Balance "); System.out.println("2- Deposit Money "); System.out.println("3- Withdraw Money "); System.out.println("4- Transfer Money "); System.out.println("5- Exit "); System.out.print("\nPlease choose a valid number : "); int Opchoice = input.nextInt(); if(Opchoice == 1) System.out.println("\nYour amount of money is "+ balance); else if (Opchoice == 2) { System.out.print("\nHow much money do you want to deposit : "); double amount = input.nextDouble(); if (amount <= 0) System.out.println("\nInvalid amount. Please enter a positive number."); else { balance += amount; money_in += amount; deposit++; if (name == account_1_name) account_1_balance = balance; else if (name == account_2_name) account_2_balance = balance; else if (name == account_3_name) account_3_balance = balance; if (balance <= 0) { System.out.println("\nYour account has no money. The account will log out."); break; } System.out.println("\nYour new amount of money is " + balance); } } else if (Opchoice == 3) { System.out.print("\nHow much money do you want to withdraw : "); double amount = input.nextDouble(); double charges = amount * 0.01; if (amount <= 0) System.out.println("\nInvalid amount. Please enter a positive number."); else { if (balance >= amount + charges) { balance -= (amount+charges); withdraw++; money_out += amount + charges; if (name == account_1_name) account_1_balance = balance; else if (name == account_2_name) account_2_balance = balance; else if (name == account_3_name) account_3_balance = balance; total_profit += charges; if (balance <= 0) { System.out.println("\nYour account has no money. The account will log out."); break; } System.out.println("\nYour new amount of money is " + balance); } else System.out.println("\nYour amount of money can't be withdrawn, not enough money!"); } } else if(Opchoice == 4) { System.out.print("\nHow much money do you want to transfer to : "); double amount = input.nextDouble(); double charges = amount * 0.025; if (amount <= 0) System.out.println("\nInvalid amount. Please enter a positive number."); else { if(balance >= amount + charges) { balance -= (amount + charges); transfer++; money_out += amount + charges; if (name == account_1_name) account_1_balance = balance; else if (name == account_2_name) account_2_balance = balance; else if (name == account_3_name) account_3_balance = balance; total_profit += charges; while(true) { System.out.print("Who do you want to transfer to : "); if(name == account_1_name) { System.out.println("\n1- " + account_2_name); System.out.println("2- " + account_3_name); int user_choice = input.nextInt(); if(user_choice == 1) { account_2_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else if (user_choice == 2) { account_3_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else System.out.println("\nPlease enter a valid number (1 -> 2)"); } else if (name == account_2_name) { System.out.println("\n1- " + account_1_name); System.out.println("2- " + account_3_name); int user_choice = input.nextInt(); if(user_choice == 1) { account_1_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else if (user_choice == 2) { account_3_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else System.out.println("\nPlease enter a valid number (1 -> 2)"); } else if (name == account_3_name) { System.out.println("\n1- " + account_1_name); System.out.println("2- " + account_2_name); int user_choice = input.nextInt(); if(user_choice == 1) { account_1_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else if (user_choice == 2) { account_2_balance += amount; System.out.println("\nYour money has been transferred successfully !!"); break; } else System.out.println("\nPlease enter a valid number (1 -> 2)"); } } if (balance <= 0) { System.out.println("\nYour account has no money. The account will log out."); break; } } else System.out.println("\nYour amount of money can't be withdrawn, not enough money! "); } } else if(Opchoice == 5) { total_deposit += deposit; total_withdraw += withdraw; total_transfer += transfer; System.out.println("\n********** Transactions Summary **********\n"); System.out.println("The number of deposit = " + deposit); System.out.println("The number of withdraw = " + withdraw); System.out.println("The number of transfer = " + transfer); System.out.println("Total money into the account = " + money_in); System.out.println("Total money out of the account = " + money_out + "\n"); break; } else System.out.println("\nPlease enter a valid number (1 -> 5)"); } } else if (choice == 4) while(true) { System.out.println("\n********** Administrator Menu **********\n"); System.out.println("\n1- View total profit "); System.out.println("2- Most popular operation "); System.out.println("3- Exit \n"); System.out.print("\nPlease choose a valid number : "); int admin_choice = input.nextInt(); if (admin_choice == 1) System.out.println("\nThe total profit is : "+ total_profit); else if (admin_choice == 2) { if(total_deposit > total_transfer && total_deposit > total_withdraw) System.out.println("\nThe most popular operation is Deposit."); else if(total_transfer > total_deposit && total_transfer > total_withdraw) System.out.println("\nThe most popular operation is Transfer."); else if(total_withdraw > total_deposit && total_withdraw > total_transfer) System.out.println("\nThe most popular operation is Withdraw."); else if (total_deposit == total_transfer && total_deposit > total_withdraw) System.out.println("\nhe most popular operation is Deposit and transfer"); else if (total_deposit == total_withdraw && total_deposit > total_transfer) System.out.println("\nThe most popular operation is Deposit and withdraw"); else if (total_transfer == total_withdraw && total_transfer > total_deposit) System.out.println("\nThe most popular operation is transfer and withdraw"); else if(total_transfer == total_deposit && total_transfer == total_withdraw) System.out.println("\nAll operations are equally popular"); } else if(admin_choice == 3) break; else System.out.println("\nPlease enter a valid number (1 -> 3)"); } else if (choice == 5) { System.out.println("\n********** Thanks for using our bank. see you latter **********"); break; } else System.out.println("\nPlease enter a valid number (1 -> 5)"); } } }
Editor is loading...
Leave a Comment