Created
November 1, 2021 15:57
-
-
Save Chaitanya-Pratap-Singh/5b6a95e2d237e125969757f3eacb7aed to your computer and use it in GitHub Desktop.
Simple Java Program Code Similar to ATM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.Scanner; | |
public class ATM { | |
private double totalBal = 100; | |
Scanner scanner = new Scanner(System.in); | |
public int userAccount() { | |
System.out.println("Enter Your Account Number"); | |
int account = scanner.nextInt(); | |
return account; | |
} | |
public int userPin() { | |
System.out.println("Enter your PIN"); | |
int pin = scanner.nextInt(); | |
return pin; | |
} | |
public void drawMainMenu() { | |
System.out.println("\nATM MAIN MENU"); | |
System.out.println("1 - View Account Balance"); | |
System.out.println("2 - Withdraw Funds"); | |
System.out.println("3 - Add Funds"); | |
System.out.println("4 - Terminate Transaction"); | |
int con = scanner.nextInt(); | |
switch (con) { | |
case 1: | |
viewAccountInfo(); | |
break; | |
case 2: | |
withDraw(); | |
break; | |
case 3: | |
addFunds(); | |
break; | |
case 4: | |
System.out.println("Thanks For Visiting"); | |
break; | |
} | |
} | |
public void withDraw() { | |
int withdrawSelection; | |
System.out.println("Withdraw money:"); | |
System.out.println("1 - 20"); | |
System.out.println("2 - ₹40"); | |
System.out.println("3 - ₹60"); | |
System.out.println("4 - ₹100"); | |
System.out.println("5 - Back to main menu"); System.out.print("Choice: "); | |
withdrawSelection =scanner.nextInt(); | |
switch (withdrawSelection) { | |
case 1: | |
checkNsf(20); | |
drawMainMenu(); | |
break; | |
case 2: | |
checkNsf(40); | |
drawMainMenu(); | |
break; | |
case 3: | |
checkNsf(60); | |
drawMainMenu(); | |
break; | |
case 4: | |
checkNsf (100); drawMainMenu(); | |
break; | |
case 5: | |
drawMainMenu(); | |
break; | |
} | |
} | |
public void viewAccountInfo() { | |
System.out.println("Account Information:"); | |
System.out.println("\t--Total balance: ₹" + totalBal); | |
drawMainMenu(); | |
} | |
public void deposit(int depAmount) { | |
System.out.println("\n**Please insert your money now...**"); | |
totalBal = totalBal + depAmount; | |
} | |
public void checkNsf(int withdrawAmount) { | |
if (totalBal - withdrawAmount < 8) System.out.println("\n**ERROR!!! Insufficient funds in you accout**"); | |
else { | |
totalBal = totalBal - withdrawAmount; | |
System.out.println("\n**Please take your money now...**"); | |
} | |
} | |
public void addFunds() { | |
int addSelection; | |
System.out.println("Deposit funds:"); | |
System.out.println("1 - ₹20"); | |
System.out.println("2 - ₹40"); | |
System.out.println("3 - ₹60"); | |
System.out.println("4 - ₹100"); | |
System.out.println("5 - Back to main menu"); | |
System.out.print("Choice: "); | |
addSelection = scanner.nextInt(); | |
switch (addSelection) { | |
case 1: | |
deposit(20); | |
drawMainMenu(); | |
break; | |
case 2: | |
deposit(40); | |
drawMainMenu(); | |
break; | |
case 3: | |
deposit(60); | |
drawMainMenu(); | |
break; | |
case 4: | |
deposit(100); | |
drawMainMenu(); | |
break; | |
case 5: | |
drawMainMenu(); | |
break; | |
} | |
} | |
public void startATM() | |
{ | |
userAccount(); | |
userPin(); | |
drawMainMenu(); | |
} | |
public static void main(String args[]) | |
{ ATM myAtm = new ATM(); | |
myAtm.startATM(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment