Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class simpleBank {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int pin = 1234, pin_attempts = 3, user_pin_try, user_choice;
- double balance = 340.0, withdraw_limit = 500, user_transfer_money;
- boolean continue_banking = true, input_valid;
- // A simple greeting
- System.out.println("Welcome to Jan Bank");
- System.out.println("");
- //login part of the script
- System.out.println("Please enter your 4 digit PIN.");
- user_pin_try = keyboard.nextInt();
- while (pin_attempts > 1) {
- if (user_pin_try == pin) {
- break;
- }
- else {
- pin_attempts -= 1;
- System.out.println("Wrong PIN, you have " + pin_attempts + " attempt(s) remaining.");
- System.out.println("Please enter your 4 digit PIN.");
- user_pin_try = keyboard.nextInt();
- }
- }
- // once they have logged in
- if (pin == user_pin_try){
- System.out.println("Access Granted");
- while (continue_banking) {
- System.out.println("");
- System.out.println("What would you like to do?");
- System.out.println(" Enter 1 to withdraw money");
- System.out.println(" Enter 2 to deposit money");
- System.out.println(" Enter 3 to view your current balance");
- System.out.println(" Enter 4 to quit");
- user_choice = keyboard.nextInt();
- // 1, they want to take money out of their account
- input_valid = false;
- if (user_choice == 1) {
- while (input_valid == false) {
- System.out.println("How much money would you like to withdraw? (Enter 0 to cancel)");
- System.out.println("Your current balance is $" + balance);
- System.out.println("You can withdraw up to $" + withdraw_limit);
- user_transfer_money = keyboard.nextDouble();
- // 0, the user wants to cancel
- if (user_transfer_money == 0) {
- input_valid = true;
- System.out.println("Action Canceled");
- }
- // the user goes over the limit
- else if (user_transfer_money > withdraw_limit){
- System.out.println("You cannot withdraw $" + user_transfer_money + ", limit is $" + withdraw_limit);
- }
- // they do not have enough money
- else if (user_transfer_money > balance){
- System.out.println("You cannot withdraw $" + user_transfer_money + ", you only have $" + balance);
- }
- // the input is correct
- else{
- balance -= user_transfer_money;
- System.out.println("You new balance is $" + balance);
- input_valid = true;
- }
- }
- }
- // the user wants to add money
- input_valid = false;
- else if (user_choice == 2) {
- while (input_valid == false){
- System.out.println("How much would you like to deposit? (Enter 0 to cancel");
- System.out.println("Your current balance is $" + balance);
- user_transfer_money = keyboard.nextDouble();
- // 0, the user wants to cancel
- if (user_transfer_money == 0) {
- input_valid = true;
- System.out.println("Action Canceled");
- }
- else {
- balance += user_transfer_money;
- System.out.println("You new balance is $" + balance);
- input_valid = true;
- }
- }
- }
- // user want to check balance
- else if (user_choice == 3) {
- System.out.println("Your current balance is $" + balance);
- }
- else if (user_choice == 4) {
- System.out.println("Ending Session");
- }
- else {
- System.out.println("Invalid Input");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement