Last active
January 19, 2022 21:20
-
-
Save dimitar-mihov17/4576ff6a79f7aaebe301355e3cafba48 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
package Banking; | |
import java.util.Scanner; | |
public class BankingApplication { | |
public static void main(String[] args) { | |
BankAccount obj1 = new BankAccount("XYZ","BA0001"); | |
obj1.showMenu(); | |
} | |
} | |
class BankAccount{ | |
int balance; | |
int previousTransaction; | |
String customerName; | |
String customerId; | |
BankAccount(String cname,String cid){ | |
customerName = cname; | |
customerId = cid; | |
} | |
void deposit(int amount){ | |
if (amount != 0){ | |
balance = balance + amount; | |
previousTransaction = amount; | |
} | |
} | |
void withdraw(int amount){ | |
if(amount != 0){ | |
balance = balance - amount; | |
previousTransaction = -amount; | |
} | |
} | |
void getPreviousTransaction(){ | |
if(previousTransaction > 0){ | |
System.out.println("Deposited: " + previousTransaction); | |
} | |
else if(previousTransaction < 0){ | |
System.out.println("Withdraw: " + Math.abs(previousTransaction)); | |
} | |
else{ | |
System.out.println("No transaction occured"); | |
} | |
} | |
void showMenu(){ | |
char option='\0'; | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Welcome " + customerName); | |
System.out.println("Your ID is " + customerId); | |
System.out.println("\n"); | |
System.out.println("A. Check Balance"); | |
System.out.println("B. Deposit"); | |
System.out.println("C. Withdraw"); | |
System.out.println("D. Previous transaction"); | |
System.out.println("E. Exit"); | |
do{ | |
System.out.println("==============================================================="); | |
System.out.println("Enter an option"); | |
System.out.println("==============================================================="); | |
option = scanner.next().charAt(0); | |
System.out.println("\n"); | |
switch(option){ | |
case 'A': | |
System.out.println("-------------------------------------------------------"); | |
System.out.println("Balance = " + balance); | |
System.out.println("-------------------------------------------------------"); | |
System.out.println("\n"); | |
break; | |
case 'B': | |
System.out.println("-------------------------------------------------------"); | |
System.out.println("Enter an amount to deposit:"); | |
System.out.println("-------------------------------------------------------"); | |
int amount = scanner.nextInt(); | |
deposit(amount); | |
System.out.println("\n"); | |
break; | |
case 'C': | |
System.out.println("-------------------------------------------------------"); | |
System.out.println("Enter an amount to withdraw:"); | |
System.out.println("-------------------------------------------------------"); | |
int amount2 = scanner.nextInt(); | |
withdraw(amount2); | |
System.out.println("\n"); | |
break; | |
case 'D': | |
System.out.println("-------------------------------------------------------"); | |
getPreviousTransaction(); | |
System.out.println("-------------------------------------------------------"); | |
System.out.println("\n"); | |
break; | |
case 'E': | |
System.out.println("-------------------------------------------------------"); | |
break; | |
default: | |
System.out.println("Invalid Option. Please enter again"); | |
break; | |
} | |
}while(option != 'E'); | |
System.out.println("Thank you for using our services"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment