Skip to content

Instantly share code, notes, and snippets.

@silageman
Created January 28, 2016 21:51
Show Gist options
  • Save silageman/e5d6006ce72f6e6404b9 to your computer and use it in GitHub Desktop.
Save silageman/e5d6006ce72f6e6404b9 to your computer and use it in GitHub Desktop.
atm test
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author lenovo - Eoin O'Dowd
*/
public class test {
private static double balance = 10.01;
private static int pin = 0000;
private static double cashwithdrawbalance;
private static int i = 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException {
try {
statementmethod();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static int displaymenu(){
System.out.println("*********ATM*********");
System.out.println("* 1: Print balance *");
System.out.println("* 2: Withdraw money *");
System.out.println("* 3: Lodge *");
System.out.println("* 4: Change pin *");
System.out.println("* 5: Mini statement *");
System.out.println("*********************");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
return selection;
}
public static void statementmethod() throws InterruptedException {
int menuoption;
menuoption = displaymenu();
if (menuoption == 1) {
System.out.println("you selected print balance, press 1 to continue, other for main menu");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
if (selection == 1) {
displaybalance();
} else {
System.out.println("ERROR - Returning to main menu");
statementmethod();
}
} else if (menuoption == 2) {
System.out.println("you selected withdraw cash, press 1 to continue, other for main menu");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
if (selection == 1) {
withdraw();
} else {
System.out.println("ERROR - Returning to main menu");
statementmethod();
}
} else if (menuoption == 3) {
System.out.println("you selected lodge, press 1 to continue, other for main menu");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
if (selection == 1) {
lodgefunds();
} else {
System.out.println("ERROR - Returning to main menu");
statementmethod();
}
} else if (menuoption == 4) {
System.out.println("you selected change pin, press 1 to continue, other for main menu");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
if (selection == 1) {
changepin();
} else {
System.out.println("ERROR - Returning to main menu");
statementmethod();
}
} else if (menuoption == 5) {
System.out.println("you selected mini statement, press 1 to continue, other for main menu");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
if (selection == 1) {
ministatement();
} else {
System.out.println("ERROR - Returning to main menu");
statementmethod();
}
}
}
public static void displaybalance() throws InterruptedException {
while(true){
//balance data from database code here
System.out.println(balance);
Thread.sleep(4000);
}
}
public static void withdraw() throws InterruptedException {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the amount you wish to withdraw: ");
Double withdraw = scan.nextDouble();
if(withdraw > balance){
System.out.println("Sorry Insufficient Funds");
withdraw();
}
else{
cashwithdrawbalance = balance - withdraw;
System.out.println("Your new balance is: "+ cashwithdrawbalance);
System.out.println("");
try {
statementmethod();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void lodgefunds(){
System.out.println("Please enter cash money: ");
}
public static void changepin() throws InterruptedException {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a new PIN");
System.out.print("PIN ->");
int pinchange = scan.nextInt();
System.out.println("Your new pin is: " + pinchange + " Press 1 to retry, other to accept new PIN");
int selection = scan.nextInt();
if(selection == 1){
changepin();
}
else{
pin = pinchange;
System.out.println("Your PIN has been changed.");
System.out.println("");
try {
statementmethod();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void ministatement(){
//get data from the server
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment