JAVA MINI PROJECT || ATM MACHINE || UNKNOWN STUDENT
JAVA MINI PROJECT
ATM MACHINE
In this project we developed a code on ATM MAchine which has multiple functionality . It is in two parts or say it was developed in two classes . The first one is MainBranch and second is Account class . Below are the following code file and do your project.
OUTPUT -
CODE -
Account class code which is inherited in Main Branch-
package com.company;
import java.util.Scanner;
class InvalidDetailException extends Exception
{
InvalidDetailException()
{
System.out.println("INVALID DETAILS ");
}
}
class MismatchDetailException extends Exception
{
MismatchDetailException()
{
System.out.println("Id and Password Mismatched-");
}
}
public class Account
{
Scanner sc = new Scanner(System.in);
void AccPutDetails()
{
int acn = 123456789 ;
int pin = 1234;
System.out.println("Enter your Linked Mobile Number -");
int ano = sc.nextInt();
System.out.println("Enter your Pin - ");
int pn = sc.nextInt();
try
{
if (ano != acn && pin != pn)
{
throw new InvalidDetailException();
}
else if (ano == acn && pin == pn)
System.out.println("Verified Successfully");
}
catch (Exception e)
{
System.out.println("You can't proceed further");
e.printStackTrace();
}
}
int [] pass = {1907007, 1907008 , 1907009 , 1907030 , 1907049};
String [] id = {"vedant_07", "kartik_08" , "pranay_09" , "prathamesh_30" , "atharva_49" };
String [] username = {"atharva" , "pranay" ,"kartik" , "prathamesh" ,"vedant"};
void OnlineBankDetails() throws MismatchDetailException
{
System.out.println("Enter your id :");
String uid = sc.next();
System.out.println("Enter your password:");
int upass = sc.nextInt();
if (pass[0] == upass && id[0].equals(uid))
{
System.out.println("Hello Vedant ");
}
else if (pass[1] == upass && id[1].equals(uid))
{
System.out.println("Hello Kartik !");
}
else if (pass[2] == upass && id[2].equals(uid))
{
System.out.println("Hello Pranay ... ");
}
else if (pass[3] == upass && id[3].equals(uid))
{
System.out.println("Hello Prathmesh !");
}
else if (pass[4] == upass && id[4].equals(uid))
{
System.out.println("Hello Atharva ");
} else throw new MismatchDetailException();
}
// throw new MismatchDetailException();
void OnlineAccount()
{
String uname;
System.out.println("Enter your name :");
uname = sc.next() ;
if ( username[0].equals(uname))
{
System.out.println("ID - atharva_49");
System.out.println("Password = 1907049");
}
else if (username[1].equals(uname) )
{
System.out.println("ID - pranay_09");
System.out.println("Password = 1907009");
}
else if (username[2].equals(uname))
{
System.out.println("ID - kartik_08");
System.out.println("Password = 1907008");
}
else if (username[3].equals(uname))
{
System.out.println("ID - prathamesh_30");
System.out.println("Password = 1907030");
}
else if ( username[4].equals(uname))
{
System.out.println("ID - vedant_07");
System.out.println("Password = 1907007");
}
else
System.out.println("Sorry ! You are not Registered .....");
}
}
MainBranch Code -
package com.company;
import java.util.Scanner;
//create ATMExample class to implement the ATM functionality
public class MainBranch extends Account
{
static class IncorrectOtpException extends Exception
{
IncorrectOtpException()
{
System.out.println("Invalid OTP");
}
}
//main method starts
public static void main(String[]args) throws IncorrectOtpException ,MismatchDetailException{
Scanner sc = new Scanner(System.in);
Account ac1 = new Account();
System.out.println("--------------------------------------------------------------------------------------------------");
System.out.println("\t\tSelect an option to proceed:\t\t" +
"\n--------------------------------------------------------------------------------------------------"+
"\nEnter (0) for proceed with Online Banking - \nEnter (1) for proceed with Mobile Number - ");
System.out.println("--------------------------------------------------------------------------------------------------");
int type = sc.nextInt();
if (type == 0)
{
ac1.OnlineBankDetails();
}
else if (type == 1)
{
ac1.AccPutDetails();
}
//declare and initialize balance, withdraw, and deposit
int balance = 0, withdraw = 0;
int deposit = 0, findp =0 , finwd = 0 , otp = 9603;
// findp , finwd is declared for mini statement........
//create scanner class object to get choice of user
// Scanner sc = new Scanner(System.in);
while (true)
{
System.out.println("---------------------------------------------------------------------");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~ATM MACHINE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
System.out.println("--------------------------------------------------------------------");
System.out.println("1 : for Withdraw");
System.out.println("____________________________________________________________________");
System.out.println("2 : for Deposit");
System.out.println("____________________________________________________________________");
System.out.println("3 : for Check Balance");
System.out.println("____________________________________________________________________");
System.out.println("4 : for Loan Limit");
System.out.println("____________________________________________________________________");
System.out.println("5 : for Mini Statement");
System.out.println("____________________________________________________________________");
System.out.println("6 : for View Details of Online Banking");
System.out.println("____________________________________________________________________");
System.out.println("7 : for EXIT");
System.out.println("____________________________________________________________________");
System.out.print("Choose the operation:");
//get choice from user
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter money to be withdrawn:");
//get the withdrawl money from user
withdraw = sc.nextInt();
//check whether the balance is greater than or equal to the withdrawal amount
if (withdraw>=10000 && withdraw <= balance)
{
System.out.println("Enter OTP Received on Your Mobile no. ");
int uotp = sc.nextInt();
if (uotp==otp)
{
System.out.println("Transaction Successful,plz collect your cash !");
if (withdraw>=10000 && withdraw <= balance)
{
balance = balance - withdraw;
finwd += withdraw;
break;
}
else
finwd = 0;
break;
}
else
throw new IncorrectOtpException();
}
else if (balance >= withdraw)
{
//remove the withdrawl amount from the total balance
balance = balance - withdraw;
System.out.println("Please collect your money");
finwd += withdraw;
} else
{
//show custom error message
System.out.println("Insufficient Balance");
}
// finwd += withdraw;
System.out.println("");
break;
case 2:
System.out.print("Enter money to be deposited:");
//get deposite amount from te user
deposit = sc.nextInt();
if (deposit <= 0)
{
System.out.println("Invalid Value");
}
else
System.out.println("Your Money has been successfully deposited");
balance = balance + deposit; //add the deposit amount to the total balanace
findp += deposit;
break;
case 3:
//displaying the total balance of the user
System.out.println("Balance : " + balance);
//System.out.println("");
break;
case 4:
System.out.println(" You choose Loan Calculator");
if (balance<=10000)
System.out.println("Sorry You are Not Eligible");
else if (balance>=20000)
System.out.println("You can apply for Loan of 10000 rs.");
else
System.out.println("You can apply for loan of 5000 Rs.");
break;
case 5 :
System.out.println("You selected Mini Statement ");
System.out.println("Total Deposits - "+ findp +"\nTotal Withdraw - "+ finwd +
"\nTotal Balance - " + balance);
break;
case 6:
System.out.println("You selected for Online Banking Details : ");
ac1.OnlineAccount();
break;
case 7:
System.out.println("Thank you for Banking with us !");
System.exit(0);
default:
throw new IllegalStateException("Unexpected value: " + choice);
}
}
}
}
Comments
Post a Comment