Created
September 30, 2015 01:08
-
-
Save 0x000000AC/a7cc23c25d10d9c1fa1f to your computer and use it in GitHub Desktop.
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
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