Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,874 members, 7,828,115 topics. Date: Wednesday, 15 May 2024 at 01:20 AM

Just For Fun: Check Out An ATM I Created With Java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Just For Fun: Check Out An ATM I Created With Java (1146 Views)

Funny Programming Memes. Just For Laughs / You Would Better Start Programming With Java Or C# / Top 20 Websites To Learn Coding With Java, Python, SQL, Algorithms, And Git For (2) (3) (4)

(1) (Reply) (Go Down)

Just For Fun: Check Out An ATM I Created With Java by salvationproject(m): 6:05pm On Dec 03, 2020
Recently started working on adding Java to my list of languages and my first class was to work on an ATM machine algorithm.

For beginners, this will definitely be great while for our professionals, it may be foolish but all the same, it is just for fun.

YOU CAN COPY CODE, RUN AND SEE THE FUN AM TALKING ABOUT.

To read code without nairaland replacement or more readability, click link:
https://wazobiatalk.com/viewthread.php?a=1219&x=check+created

//package
package com.example.pke;

//Importing necessary classes that will foster the successful implementing of the code
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

public class packard {

public static void main(String [] args){

//Scanner obj to get input from ATM user
Scanner cin = new Scanner(System.in);

//Our accounts
ArrayList<String> accounts = new ArrayList<String>();
accounts.add("Joseph Omamode"wink;
accounts.add("Glory Oko"wink;
accounts.add("Prince Oghenovo"wink;
accounts.add("Godfrey Zoe"wink;

//Our accounts' pins database in form of user full names and PIN
HashMap<String, Integer> pins = new HashMap<String, Integer>();
pins.put("Joseph Omamode",4080);
pins.put("Glory Oko",1997);
pins.put("Prince Oghenovo",2080);
pins.put("Godfrey Zoe",1331);

//Our users account type
HashMap<String, String> types = new HashMap<String, String>();
types.put("Joseph Omamode","Savings"wink;
types.put("Glory Oko","Savings"wink;
types.put("Prince Oghenovo","Current"wink;
types.put("Godfrey Zoe","Savings"wink;

//Our users account numbers
HashMap<String, Integer> act_nums = new HashMap<String, Integer>();
act_nums.put("Joseph Omamode",4080152);
act_nums.put("Glory Oko",1521997);
act_nums.put("Prince Oghenovo",2080152);
act_nums.put("Godfrey Zoe",1521331);

//Our accounts' balances database in the form of user full names and balance
HashMap<String, Integer> bals = new HashMap<String, Integer>();
bals.put("Joseph Omamode",100000);
bals.put("Glory Oko",90000);
bals.put("Prince Oghenovo",800000);
bals.put("Godfrey Zoe",120000);

//Welcome Msg
System.out.println("KARDLESS ATM MACHINE...\n\nNote:This ATM contains the Naira denomination of N1,000 and can only permit a maximum withdrawal of N20,000 at a time.\n\n"wink;

//Random number to help select a random user's account
int num = (int) (Math.random() * accounts.size());

//Card Detected - Process a transaction
String account = accounts.get(num);
//What happened above was that with the help of the random number earlier generated, we were able to select as a particular from our account array

//Check if the account really exists
if (accounts.contains(account))
{
//Print Welcome Message
System.out.println("Welcome "+account+"\n\nPLEASE WAIT...\n\nEnter your personal identification number(PIN):"wink;

//Take pin from user for this particular account
int pin = cin.nextInt();

//check if pin is correct
if (pins.get(account) == pin)
{
//Pin is correct

//Prompting user to select action to perform e.g withdrawal
System.out.println("\nSELECT AN OPTION:\n1 => Withdrawal\n2 => Account Balance Enquiry\n3 => Transfers\n4 => Account Enquiry"wink;

//Action feedback
int op = cin.nextInt();

//Let's get user account balance
int act_bal = bals.get(account);

//Let's get user account number
int act_num = act_nums.get(account);

//Let's get user account type
String type = types.get(account);

//Prompt user to confirm his/her account type
System.out.println("\nSELECT YOUR ACCOUNT TYPE\n\n1 => Current\n2 => Savings\n3 => Domicilliary"wink;

//Account type feedback
int a_type = cin.nextInt();

//Remember the account type feedback is an int. The below switch statement helps to know the account type in words in a string(s_type) so as to help compare and confirm with the real account type
String s_type = "";
switch (a_type)
{
case 1: s_type = "Current"; break;
case 2: s_type = "Savings"; break;
case 3: s_type = "Domicilliary"; break;
}

//Confirming account type
if (s_type == type)
{
//Account type confirmed

//This switch is to start processing the user wanted action/transaction/operation e.g withdrawal since account type and pins have been verified.
switch (op){
case 1:
//User wants to withdraw
System.out.println("\nWITHDRAWAL REQUEST\n\nSELECT AMOUNT:\n1 => 500\n2 => 1000\n3 => 5000\n4=> 10000\n5 => Others"wink;
int amt = 0;
//Get the amount option from options given e.g 5000 or Others
int ao = cin.nextInt();

//Switch to process the option
switch (ao)
{
case 1:
//User wants to withdraw 500
amt = 500;
break;
case 2:
//User wants to withdraw 1000
amt = 1000;
break;
case 3:
//User wants to withdraw 5000
amt = 5000;
break;
case 4:
//User wants to withdraw 10000
amt = 10000;
break;
case 5:
//User wants to manually enter amount
System.out.println("\nEnter Amount:"wink;
amt = cin.nextInt();
break;
}

//Check if amount requested is less than or equal to users account balance
if (amt <= act_bal && amt <= 20000)
{
//Yes, User is eligible to withdraw... PROCESS WITHDRAWAL and give feedback
System.out.println("\nPlease Wait While Cash Is Being Dispense:\n..................\n.................. \n..................\nTRANSACTION COMPLETE!!! Please take your cash.\nDETAILS\nAcc: "+account+"\nAmt: N"+amt+"\nBal: N"+(act_bal - amt));
}
else
{
if (amt > act_bal)
{
//Insufficient balance
System.out.println("\nTRANSACTION FAILED!!! Insufficient Balance..."wink;
}
else
{
//Requested amount exceeded the amount allowable for withdrawal in this ATM which is N20000
System.out.println("\nWithdrawal limit exceeded.\nTRANSACTION FAILED..."wink;
}
}
break;
case 2:
//User wants account balance enquiry
System.out.println("\nACCOUNT BALANCE ENQUIRY!!!\n\nAcc: "+account+"\nAcc. Type: "+type+"\nBalance: N"+act_bal);
break;
case 3:
//User wants to transfer

//User should enter destination account type
System.out.println("\nSELECT DESTINATION ACCOUNT TYPE:\n\n1 => Current\n2 => Savings\n3 => Domicilliary"wink;
int da_type = cin.nextInt();

//Switch to convert the enter destination account type to string
String d_type = "";
switch (da_type)
{
case 1: d_type = "Current"; break;
case 2: d_type = "Savings"; break;
case 3: d_type = "Domicilliary"; break;
}

//Prompting to enter destination account number
System.out.println("\nENTER DESTINATION ACCOUNT NUMBER:"wink;
int d_acc = cin.nextInt();

//The boolean and the following foreach statement will check to know if an account number with the specified type really exists among our account records
boolean a_ex = false;
for (String j : act_nums.keySet())
{
if (act_nums.get(j) == d_acc && types.get(j) == d_type)
{
//it exists

//Checking whether the destination account is same as user's account number
if (act_num == d_acc)
{
//It is... Therefore, transaction failed... Don't tell him/her much cause he/she knows what he/she is doing i.e it is insane wanting to transfer money from ur account to ur account
System.out.println("\nTRANSFER FAILED!!!"wink;
}
else
{
//It is not... Let's proceed by requesting amount to transfer from user
System.out.println("\nENTER AMOUNT:"wink;
int d_amt = cin.nextInt();

//Prompting to enable user confirm he/she understands what is going on and to either terminate transfer or proceed
System.out.println("\nTRANSFER "+d_amt+" To "+j+"\n1 => YES\n0 => NO"wink;
int t = cin.nextInt();
if (t == 0)
{
//User don't want to proceed with transfer
System.out.println("TRANSFER CANCELLED!!!"wink;
}
else
{
//User want to proceed but let's confirm if he/she has real amount in account to proceed.
if (d_amt <= act_bal)
{
//Yes... PROCESS TRANSFER and give feedback
System.out.println("\nPlease Wait While Transfer Is Processing:\n..................\n.................. \n..................\nTRANSFER SUCCESSFUL!!! Please take your card.\nDETAILS\nAcc: "+account+"\nAmt: N"+d_amt+"\nBal: N"+(act_bal - d_amt));
}
else
{
//Insufficient balance
System.out.println("Insufficient Balance."wink;
}
}
}
a_ex = true;
break;
}
}
if (a_ex == false)
{
//Account does not exists
System.out.println("FAILED!!!This is because the account number is invalid or account type is not correct...Please try again."wink;
}
break;
case 4:
//User wants to know account details
System.out.println("\nACCOUNT ENQUIRY - DETAILS!!!\n\nAcc Num: "+act_num+"\nAcc: "+account+"\nAcc. Type: "+type+"\nBalance: N"+act_bal);
break;
default:
//We couldn't recognize what user wants
System.out.println("Entry Not Recognize."wink;
break;
}

//Further communication with user after transaction
System.out.println("\n\nWANT TO PERFORM ANOTHER TRANSACTION?\n1 => YES\n2 => NO"wink;
int z = cin.nextInt();
switch (z){
case 1:
System.out.println("Please take your card and re - insert."wink;
break;
default:
System.out.println("Please take your card."wink;
break;
}
}
else
{
//User entered account type didn't match with the account type associated with this account... So, transaction failed
System.out.println("TRANSACTION FAILED!!! Please take your card..."wink;
}
}
else
{
//Incorrect PIN detected
System.out.println("\nIncorrect PIN. Please take your card."wink;
}
}
}
}

1 Like

Re: Just For Fun: Check Out An ATM I Created With Java by Juliusmomoh: 6:13pm On Dec 03, 2020
You try. But you forget something
Re: Just For Fun: Check Out An ATM I Created With Java by salvationproject(m): 6:19pm On Dec 03, 2020
Juliusmomoh:
You try. But you forget something
what could that be please?
Re: Just For Fun: Check Out An ATM I Created With Java by Juliusmomoh: 6:27pm On Dec 03, 2020
salvationproject:
what could that be please?
Am coming Lemme check_out something
Re: Just For Fun: Check Out An ATM I Created With Java by jesmond3945: 10:03pm On Dec 03, 2020
Very nice
Re: Just For Fun: Check Out An ATM I Created With Java by logicDcoder(m): 10:42pm On Dec 03, 2020
Your code would be cleaner if you break common operations there into classes and methods.
Re: Just For Fun: Check Out An ATM I Created With Java by salvationproject(m): 11:32pm On Dec 03, 2020
jesmond3945:
Very nice
tnk u
Re: Just For Fun: Check Out An ATM I Created With Java by salvationproject(m): 11:34pm On Dec 03, 2020
logicDcoder:
Your code would be cleaner if you break common operations there into classes and methods.
tnk u sir

Never really used methods cuz it was no real reusability of codes needed but just as u said, the code would have been neater
Re: Just For Fun: Check Out An ATM I Created With Java by logicDcoder(m): 11:38pm On Dec 03, 2020
salvationproject:
tnk u sir

Never really used methods cuz it was no real reusability of codes needed but just as u said, the code would have been neater
okay
Re: Just For Fun: Check Out An ATM I Created With Java by JoyousFurnitire(m): 5:05pm On Mar 08, 2022
I actually came here from your recent post, is this on GitHub? I will like to replicate it with typescript.
Re: Just For Fun: Check Out An ATM I Created With Java by salvationproject(m): 3:41pm On Mar 09, 2022
JoyousFurnitire:
I actually came here from your recent post, is this on GitHub? I will like to replicate it with typescript.
No sir
Re: Just For Fun: Check Out An ATM I Created With Java by Elporo(m): 1:55pm On Mar 10, 2022
salvationproject:

No sir

why?
Re: Just For Fun: Check Out An ATM I Created With Java by Solanaa: 10:19pm On Mar 10, 2022
Odogwu


I want to be like you oh

(1) (Reply)

Oracle Dbas-(come Around Here If U Need Help With Administering Oracle Db E.t.c) / Vb6 Programming /

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.