Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.time.*;
- public class payment {
- static String username="";
- static String password="";
- static int pin;
- static String email="";
- static double balance=0;
- static String History="";
- static void reg()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter username");
- username=in.nextLine();
- System.out.println("create password");
- password=in.nextLine();
- System.out.println("create pin");
- pin=in.nextInt();
- in.nextLine();
- System.out.println("enter email");
- email=in.nextLine();
- }
- static void login()
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("enter username");
- String username1=sc.nextLine();
- System.out.println("enter password");
- String password2=sc.nextLine();
- System.out.println("enter pin");
- int pin2=sc.nextInt();
- sc.nextLine();
- System.out.println("enter email");
- String email2=sc.nextLine();
- if(username1.equals(username) && password2.equals(password) && pin2==pin && email2.equals(email))
- {
- System.out.println("login successfull");
- accountmenu();
- }
- else {
- System.out.println("login failed");
- }
- }
- static void accountmenu()
- {
- System.out.println("account menu---->");
- Scanner in=new Scanner(System.in);
- boolean loggedin=true;
- while(loggedin)
- {
- System.out.println("1. Add money");
- System.out.println("2.withdraw money");
- System.out.println("3.send money");
- System.out.println("4.receive money");
- System.out.println("5. check balance");
- System.out.println("6.check pin");
- System.out.println("7.history");
- System.out.println("8. logout");
- System.out.println("enter choice");
- int ch=in.nextInt();
- switch(ch)
- {
- case 1:
- addmoney();
- break;
- case 2:
- withdrawmoney();
- break;
- case 3:
- sendmoney();
- break;
- case 4:
- receivemoney();
- break;
- case 5:
- checkbalance();
- break;
- case 6:
- checkpin();
- break;
- case 7:
- showhistory();
- break;
- case 8:
- loggedin=false;
- break;
- default:
- System.out.println("invalid choice");
- }
- }
- }
- static void addmoney()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter money to be added");
- double amt=in.nextInt();
- balance+=amt;
- addHistory("added--" + amt);
- }
- static void withdrawmoney()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter amount to be withdrawed");
- double amt=in.nextInt();
- if(amt>balance)
- {
- System.out.println("cannot be withdrawed");
- }
- else {
- balance=balance-amt;
- System.out.println("amt withdrawed " + amt);
- addHistory("money withdrawed: " + amt);
- }
- }
- static void sendmoney()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter amount to be sent");
- double amt=in.nextDouble();
- if(amt>balance)
- {
- System.out.println("insufficient balance");
- }
- else
- {
- balance=balance-amt;
- System.out.println("enter receiver name:");
- String st=in.nextLine();
- addHistory("sent money " + amt + " to " + st);
- System.out.println("money sent");
- }
- }
- static void receivemoney()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter amt to be received");
- double amt = in.nextDouble();
- balance=balance+amt;
- System.out.println("enter money sender name");
- String st1=in.nextLine();
- addHistory("amt received " + amt + "from " + st1);
- }
- static void checkbalance()
- {
- System.out.println("available balance: " + balance );
- }
- static void checkpin()
- {
- Scanner in=new Scanner(System.in);
- System.out.println("enter pin to be checked");
- int pin3=in.nextInt();
- if(pin3==pin)
- {
- System.out.println("entered pin is valid");
- }
- else {
- System.out.println("pin is invalid");
- }
- }
- static void showhistory()
- {
- if(History.equals(""))
- {
- System.out.println("no history");
- }
- else {
- System.out.println("history :" + History);
- }
- }
- static void addHistory(String data)
- {
- LocalDateTime now = LocalDateTime.now();
- History+= data + " | " + now + " " ;
- }
- public static void main(String []args)
- {
- while(true)
- {
- Scanner in=new Scanner(System.in);
- System.out.println("1.register if not login");
- System.out.println("2.login");
- System.out.println("3.exit");
- System.out.println("enter your choice");
- int ch=in.nextInt();
- switch(ch)
- {
- case 1:
- reg();
- break;
- case 2:
- login();
- break;
- case 3:
- System.exit(0);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment