Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Login{
- static ArrayList<String> userLogin(){
- Scanner in=new Scanner(System.in);
- ArrayList<String> lst = new ArrayList<>();
- System.out.println("Enter User ID :");
- String userName=in.nextLine();
- System.out.println("Enter User PIN :");
- String userPIN=in.nextLine();
- System.out.println("Enter your Account number :");
- Atm.accno=in.nextLine();
- System.out.println("====================================REGISTRATION SUCCESSFUL==========================================");
- lst.add(userName);
- lst.add(userPIN);
- // in.close();
- return lst;
- }
- }
- class Debit{
- static void debitAmount(){
- Scanner in=new Scanner(System.in);
- System.out.println("Enter amount to withdraw :");
- int withdrawAmount=in.nextInt();
- if(withdrawAmount<=Atm.balance){
- Atm.balance=Atm.balance-withdrawAmount;
- // Atm.transactions.add(Integer.toString(withdrawAmount));
- Atm.transactions.add("Withdrawn -"+withdrawAmount);
- System.out.println("Amount Rs"+withdrawAmount+"/- withdrawn successfully");
- }
- else{
- System.out.println("insufficient balance to withdraw the cash");
- }
- System.out.println("=========================================================================================");
- // in.close();
- }
- }
- class Credit{
- static void creditAmount(){
- Scanner in=new Scanner(System.in);
- System.out.print("Enter amount to deposit :");
- int depositAmount=in.nextInt();
- Atm.updatebalance(depositAmount);
- // Atm.transactions.add(Integer.toString(depositAmount));
- Atm.transactions.add("Deposited -"+depositAmount);
- System.out.println("Amount Rs."+depositAmount+"/- deposit successful!");
- System.out.println("=========================================================================================");
- // in.close();
- }
- }
- class Transfer{
- static void transferAmount(){
- Scanner in=new Scanner(System.in);
- System.out.println("Enter the receiving body:");
- String receiver = in.nextLine();
- System.out.println("Enter the account number of the receiving body");
- int receiverAccNum =in.nextInt();
- System.out.println("Enter the amount to be transferred :");
- int transferAmount=in.nextInt();
- if(transferAmount<=Atm.balance){
- Atm.balance=Atm.balance-transferAmount;
- // Atm.transactions.add(Integer.toString(transferAmount));
- Atm.transactions.add("Transferred -"+transferAmount);
- System.out.println("Amount Rs."+transferAmount+"/- transferred successfully");
- }
- else{
- System.out.println("insufficient balance to transfer the cash");
- }
- System.out.println("=========================================================================================");
- // in.close();
- }
- }
- class Balance{
- static void balanceEnquiry(){
- System.out.println("The available balance is : ");
- Atm.showbalance();
- System.out.println("=========================================================================================");
- }
- }
- class History{
- static void transactionHistory(ArrayList<String> userData){
- System.out.println("Transaction History :");
- int k=1;
- System.out.println("User Name : "+userData.get(0));
- if(Atm.transactions.size()!=0){
- for(String i : Atm.transactions){
- System.out.println("ID."+(k++)+" "+i);
- }
- }else{
- System.out.println("There are no transactions");
- }
- System.out.println("=========================================================================================");
- }
- }
- public class Atm {
- public static String name;
- public static int balance=0;
- public static String accno;
- public static ArrayList<String> transactions=new ArrayList<>();
- static void updatebalance(int depositAmount){
- balance=balance+depositAmount;
- }
- static void showbalance(){
- System.out.println(balance);
- }
- static void dashboard(ArrayList<String> arr){
- Scanner in=new Scanner(System.in);
- System.out.println("Choose one of the following options: ");
- System.out.println("1. Deposit");
- System.out.println("2. Withdraw");
- System.out.println("3. Transfer");
- System.out.println("4. Check balance");
- System.out.println("5. Transaction History");
- System.out.println("6. Exit");
- System.out.print("Option -> ");
- int option=in.nextInt();
- switch (option) {
- case 1:
- Credit.creditAmount();
- break;
- case 2:
- Debit.debitAmount();
- break;
- case 3:
- Transfer.transferAmount();
- break;
- case 4:
- Balance.balanceEnquiry();
- break;
- case 5:
- History.transactionHistory(arr);
- break;
- case 6:
- in.close();
- System.exit(0);
- }
- dashboard(arr);
- }
- public static void main(String[] args) {
- System.out.printf("%n==================================== WELCOME TO ATM INTERFACE ====================================%n");
- ArrayList<String> user = new ArrayList<>();
- user = Login.userLogin();
- Atm.dashboard(user);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement