Skip to content

Instantly share code, notes, and snippets.

@0x000000AC
Created September 30, 2015 01:08
Show Gist options
  • Save 0x000000AC/a7cc23c25d10d9c1fa1f to your computer and use it in GitHub Desktop.
Save 0x000000AC/a7cc23c25d10d9c1fa1f 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;
String userInput;
Scanner in = new Scanner(System.in);
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");
}
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");
}
else if (userInput.equalsIgnoreCase("balance"))
{
System.out.print("Your current balance is: " + balance + "\n");
}
else
{
System.out.print("The string you entered does not match an action, try again.\n");
}
} // end main
} // end Atm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment