Skip to content

Instantly share code, notes, and snippets.

@0x000000AC
Created September 30, 2015 01:42
Show Gist options
  • Save 0x000000AC/d36c39fbf70fba7b0142 to your computer and use it in GitHub Desktop.
Save 0x000000AC/d36c39fbf70fba7b0142 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Atm
{
public static void main(String[] args)
{
double balance = 100.00;
double withdrawalAmount;
double depositAmount;
boolean sentinelValue = true;
String userInput;
String sentinel;
Scanner scnr = new Scanner(System.in);
Scanner in = new Scanner(System.in);
while (sentinelValue == true)
{
System.out.println("Type an action...");
System.out.println("Balance, Deposit or Withdrawal: ");
userInput = in.nextLine();
if (userInput.equalsIgnoreCase("deposit"))
{
System.out.print("Enter amount to deposit: ");
depositAmount = in.nextDouble();
balance += depositAmount;
System.out.println("Your current balance is: " + balance + "\n");
System.out.print("Continue? (Y or N)\n");
sentinel = scnr.nextLine();
if (sentinel.equalsIgnoreCase("y"))
{
sentinelValue = true;
}
else
{
sentinelValue = false;
}
}
else if (userInput.equalsIgnoreCase("withdrawal"))
{
System.out.print("Enter amount to withdrawal: ");
withdrawalAmount = in.nextDouble();
balance -= withdrawalAmount;
if (balance < 0 )
{
System.out.println("Sorry, you cannot take more than is available.\n");
balance = 100.00;
}
System.out.println("Your current balance is: " + balance + "\n");
System.out.print("Continue? (Y or N)\n");
sentinel = scnr.nextLine();
if (sentinel.equalsIgnoreCase("y"))
{
sentinelValue = true;
}
else
{
sentinelValue = false;
}
}
else if (userInput.equalsIgnoreCase("balance"))
{
System.out.print("Your current balance is: " + balance + "\n");
System.out.print("Continue? (Y or N)\n");
sentinel = scnr.nextLine();
if (sentinel.equalsIgnoreCase("y"))
{
sentinelValue = true;
}
else
{
sentinelValue = false;
}
}
else
{
System.out.print("The string you entered does not match an action, try again.\n");
System.out.print("Continue? (Y or N)\n");
sentinel = scnr.nextLine();
if (sentinel.equalsIgnoreCase("y"))
{
sentinelValue = true;
}
else
{
sentinelValue = false;
}
}
} // end while
} // end main
} // end Atm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment