Oop Final Project

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

OOP FINAL PROJECT | ATM MACHINE PROGRAM IN JAVA

BY: JHERRY S. DELEON, WMAD 2A

package atm_function;
import java.util.Scanner;

abstract class BankAccount {


private float savings;

float withdraw(float money, float savings) {


if (savings >= money)
this.savings = savings - money;
else
this.savings = savings;

return this.savings;
}
}

class BankAccount1 extends BankAccount {


private float saving;

float deposit(float saving, float deposit) {


this.saving = saving + deposit;

System.out.println("\tDeposit successful!");
return this.saving;
}

@Override
float withdraw(float pera, float savings) {

if (savings >= pera){


savings = super.withdraw(pera, savings);
System.out.println("\tWidthdrawal successful!");
}
else
System.out.println("\tInsufficient Funds\n");

return savings;
}

class Multi{
private float savings1,savings2,savings3,savings4,savings5;

Multi(float savings1, float savings2, float savings3, float savings4, float savings5){
this.savings1=savings1;
this.savings2=savings2;
this.savings3=savings3;
this.savings4=savings4;
this.savings5=savings5;
}

void withdrawOperation(Scanner scanner, BankAccount1 user1,BankAccount1 user2,BankAccount1 user3,BankAccount1


user4,BankAccount1 user5, float savings1, float savings2, float savings3, float savings4, float savings5) {
System.out.print("\tAmount to withdraw: ₱ ");
float amnt = scanner.nextFloat();
System.out.print("\tInput user number (1 to 5): ");
int userIndex = scanner.nextInt();
switch (userIndex) {
case 1:
this.savings1 = user1.withdraw(amnt, this.savings1);
break;
case 2:
this.savings2 = user2.withdraw(amnt, this.savings2);
break;
case 3:
this.savings3 = user3.withdraw(amnt, this.savings3);
break;
case 4:
this.savings4 = user4.withdraw(amnt, this.savings4);
break;
case 5:
this.savings5 = user5.withdraw(amnt, this.savings5);
break;
default:
System.out.println("Invalid user index. Please try again.\n");
break;
}
}

void depositOperation(Scanner scanner, BankAccount1 user1,BankAccount1 user2,BankAccount1 user3,BankAccount1


user4,BankAccount1 user5, float savings1, float savings2, float savings3, float savings4, float savings5) {
System.out.print("\tAmount to deposit: ₱ ");
float deposited = scanner.nextFloat();
System.out.print("\tInput user number (1 to 5) ");
int userIndex = scanner.nextInt();
switch (userIndex) {
case 1:
this.savings1 = user1.deposit(this.savings1, deposited);
break;
case 2:
this.savings2 = user2.deposit(this.savings2, deposited);
break;
case 3:
this.savings3 = user3.deposit(this.savings3, deposited);
break;
case 4:
this.savings4 = user4.deposit(this.savings4, deposited);
break;
case 5:
this.savings5 = user5.deposit(this.savings5, deposited);
break;
default:
System.out.println("\tInvalid user index. Please try again.\n");
break;
}
}

void checkBalanceOperation(Scanner scanner, float savings1, float savings2, float savings3, float savings4, float savings5)
{
System.out.print("Input user number (1 to 5): ");
int userIndex = scanner.nextInt();
if (userIndex < 1 || userIndex > 5) {
System.out.print("Invalid Input.\n");
} else {
switch (userIndex) {
case 1:
System.out.println("\tBalance: ₱ " + this.savings1);
break;
case 2:
System.out.println("\tBalance: ₱ " + this.savings2);
break;
case 3:
System.out.println("\tBalance: ₱ " + this.savings3);
break;
case 4:
System.out.println("\tBalance: ₱ " + this.savings4);
break;
case 5:
System.out.println("\tBalance: ₱ " + this.savings5);
break;
default:
break;
}
}
}

void exitOperation() {
System.out.println("Exiting Program!\n");
System.out.println("----------------------------------------------------");
System.out.println("Welcome to D-Bank ATM!");
System.out.println("Insert your card to begin the transaction.");
}
}

public final class ATM_Function {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
BankAccount1 user1 = new BankAccount1();
BankAccount1 user2 = new BankAccount1();
BankAccount1 user3 = new BankAccount1();
BankAccount1 user4 = new BankAccount1();
BankAccount1 user5 = new BankAccount1();

float savings1 = 10000, savings2 = 20000, savings3 = 30000, savings4 = 40000, savings5 = 50000;
Multi nat = new Multi(savings1,savings2,savings3,savings4,savings5);

System.out.println("Welcome to D-Bank ATM!");


System.out.println("Insert your card to begin the transaction.");

while (true) {
System.out.println("\n1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Check Balance");
System.out.println("4. Exit");

System.out.print("\nEnter the corresponding number for your choice: ");


int userInput = scanner.nextInt();

switch (userInput) {
case 1:
nat.withdrawOperation(scanner, user1,user2,user3,user4,user5,savings1, savings2, savings3, savings4,
savings5);
break;

case 2:
nat.depositOperation(scanner, user1,user2,user3,user4,user5,savings1, savings2, savings3, savings4, savings5);
break;

case 3:
nat.checkBalanceOperation(scanner, savings1, savings2, savings3, savings4, savings5);
break;

case 4:
nat.exitOperation();
continue;

default:
System.out.println("Invalid Input.\n");
}
}
}
}

You might also like