5
Fri Mar 22 2024 22:11:54 GMT+0000 (Coordinated Universal Time)
Saved by @abdul_rehman #java
BankAccount.java
import java.util.Scanner;
public class BankAccount {
String name;
private double balance;
private int depositCount = 0;
private int withdrawCount = 0;
private String accountType;
public void deposit(double amount){
balance += amount;
System.out.println(amount + " is successfully Deposited");
depositCount++;
if(balance > 100000){
balance = balance + (amount / 100);
}
}
public void setAccountType(String type){
this.accountType = type;
}
public void withdraw(double amount){
if(balance >= amount){
if(balance - amount < 50000){
System.out.println("Asre you sure you want to withdraw, it would make your balance below 50,000");
System.out.println("Press 1 to continue and 0 to abort");
Scanner input = new Scanner(System.in);
int confirm = input.nextInt();
if(confirm != 1){
System.out.println("Withdrawal aborted");
return;
}
}
double withdrawAmount = amount;
if(balance < 50000){
withdrawAmount = withdrawAmount + amount * 0.02;
withdrawCount++;
}
balance = balance - withdrawAmount;
System.out.println(withdrawAmount + " is successfully withdrawn");
}
else{
System.out.println("Insufficient funds");
}
}
public double getBalance(){
return balance;
}
public void subscribeSmsAlert(){
if(accountType.equals("STANDARD")){
balance -= 2000;
}
}
public void subscribeDebitCard(){
if(accountType.equals("STANDARD")){
balance -= 5000;
}
}
void transaction(){
System.out.println("Account title: " + name);
System.out.println("Total deposit: " + depositCount);
System.out.println("Total withdraw: " + withdrawCount);
System.out.println("Balance: " + balance);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//BankAccountTest.Java
import java.util.Scanner;
public class BankAccountTest{
public static void main(String args[]){
BankAccount account = new BankAccount();
Scanner input = new Scanner(System.in);
account.name = "Maan";
System.out.println("Enter the account type: ");
String accountType = input.nextLine();
account.setAccountType(accountType);
System.out.println("Do want to subscribe SMS alerts(Y or N): ");
String sms = input.nextLine();
if(sms.equals("Y") || sms.equals("y")){
account.subscribeSmsAlert();
}
System.out.println("Do you want to subscribe Debit Card(Y or N): ");
String debit = input.nextLine();
if(debit.equals("Y") || debit.equals("y")){
account.subscribeDebitCard();
}
int choice;
do{
System.out.println("Press 1: To Deposit an amount\nPress 2: To Withdraw an amount\nPress 3: To View the current balance\nPress 4: To Close the program");
choice = input.nextInt();
switch(choice){
case 1:
System.out.println("Enter the amount you want to Deposite");
double depositeAmount = input.nextDouble();
account.deposit(depositeAmount);
break;
case 2:
System.out.println("Enter the amount you want to withdraw");
double withdrawAmount = input.nextDouble();
account.withdraw(withdrawAmount);
break;
case 3:
System.out.println("Your current balance is " + account.getBalance());
break;
case 4:
System.out.println("The program is terminated");
account.transaction();
break;
default:
System.out.println("Incorrect choice. Please try again!");
break;
}
}while(choice!=4);
}
}



Comments