Dazai_90281

Untitled

Dec 14th, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. import java.util.*;
  2. import java.time.*;
  3. public class payment {
  4. static String username="";
  5. static String password="";
  6. static int pin;
  7. static String email="";
  8. static double balance=0;
  9. static String History="";
  10.  
  11. static void reg()
  12. {
  13. Scanner in=new Scanner(System.in);
  14. System.out.println("enter username");
  15. username=in.nextLine();
  16. System.out.println("create password");
  17. password=in.nextLine();
  18. System.out.println("create pin");
  19. pin=in.nextInt();
  20. in.nextLine();
  21. System.out.println("enter email");
  22. email=in.nextLine();
  23. }
  24. static void login()
  25. {
  26. Scanner sc=new Scanner(System.in);
  27. System.out.println("enter username");
  28. String username1=sc.nextLine();
  29. System.out.println("enter password");
  30. String password2=sc.nextLine();
  31. System.out.println("enter pin");
  32. int pin2=sc.nextInt();
  33. sc.nextLine();
  34. System.out.println("enter email");
  35. String email2=sc.nextLine();
  36. if(username1.equals(username) && password2.equals(password) && pin2==pin && email2.equals(email))
  37. {
  38. System.out.println("login successfull");
  39. accountmenu();
  40. }
  41. else {
  42. System.out.println("login failed");
  43. }
  44.  
  45. }
  46. static void accountmenu()
  47. {
  48. System.out.println("account menu---->");
  49. Scanner in=new Scanner(System.in);
  50.  
  51. boolean loggedin=true;
  52. while(loggedin)
  53. {
  54. System.out.println("1. Add money");
  55. System.out.println("2.withdraw money");
  56. System.out.println("3.send money");
  57. System.out.println("4.receive money");
  58. System.out.println("5. check balance");
  59. System.out.println("6.check pin");
  60. System.out.println("7.history");
  61. System.out.println("8. logout");
  62. System.out.println("enter choice");
  63. int ch=in.nextInt();
  64. switch(ch)
  65. {
  66. case 1:
  67. addmoney();
  68. break;
  69. case 2:
  70. withdrawmoney();
  71. break;
  72. case 3:
  73. sendmoney();
  74. break;
  75. case 4:
  76. receivemoney();
  77. break;
  78. case 5:
  79. checkbalance();
  80. break;
  81. case 6:
  82. checkpin();
  83. break;
  84. case 7:
  85. showhistory();
  86. break;
  87. case 8:
  88. loggedin=false;
  89. break;
  90. default:
  91. System.out.println("invalid choice");
  92. }
  93. }
  94. }
  95. static void addmoney()
  96. {
  97. Scanner in=new Scanner(System.in);
  98. System.out.println("enter money to be added");
  99. double amt=in.nextInt();
  100. balance+=amt;
  101. addHistory("added--" + amt);
  102. }
  103. static void withdrawmoney()
  104. {
  105. Scanner in=new Scanner(System.in);
  106. System.out.println("enter amount to be withdrawed");
  107. double amt=in.nextInt();
  108.  
  109. if(amt>balance)
  110. {
  111. System.out.println("cannot be withdrawed");
  112. }
  113. else {
  114. balance=balance-amt;
  115. System.out.println("amt withdrawed " + amt);
  116. addHistory("money withdrawed: " + amt);
  117. }
  118. }
  119. static void sendmoney()
  120. {
  121. Scanner in=new Scanner(System.in);
  122. System.out.println("enter amount to be sent");
  123. double amt=in.nextDouble();
  124. if(amt>balance)
  125. {
  126. System.out.println("insufficient balance");
  127. }
  128. else
  129. {
  130. balance=balance-amt;
  131. System.out.println("enter receiver name:");
  132. String st=in.nextLine();
  133. addHistory("sent money " + amt + " to " + st);
  134. System.out.println("money sent");
  135. }
  136. }
  137. static void receivemoney()
  138. {
  139. Scanner in=new Scanner(System.in);
  140. System.out.println("enter amt to be received");
  141. double amt = in.nextDouble();
  142. balance=balance+amt;
  143. System.out.println("enter money sender name");
  144. String st1=in.nextLine();
  145. addHistory("amt received " + amt + "from " + st1);
  146.  
  147. }
  148. static void checkbalance()
  149. {
  150. System.out.println("available balance: " + balance );
  151. }
  152.  
  153. static void checkpin()
  154. {
  155. Scanner in=new Scanner(System.in);
  156. System.out.println("enter pin to be checked");
  157. int pin3=in.nextInt();
  158. if(pin3==pin)
  159. {
  160. System.out.println("entered pin is valid");
  161. }
  162. else {
  163. System.out.println("pin is invalid");
  164. }
  165.  
  166. }
  167.  
  168. static void showhistory()
  169. {
  170. if(History.equals(""))
  171. {
  172. System.out.println("no history");
  173. }
  174. else {
  175. System.out.println("history :" + History);
  176. }
  177. }
  178.  
  179.  
  180. static void addHistory(String data)
  181. {
  182. LocalDateTime now = LocalDateTime.now();
  183. History+= data + " | " + now + " " ;
  184. }
  185. public static void main(String []args)
  186. {
  187. while(true)
  188. {
  189.  
  190. Scanner in=new Scanner(System.in);
  191. System.out.println("1.register if not login");
  192. System.out.println("2.login");
  193. System.out.println("3.exit");
  194. System.out.println("enter your choice");
  195. int ch=in.nextInt();
  196. switch(ch)
  197. {
  198. case 1:
  199. reg();
  200. break;
  201. case 2:
  202. login();
  203. break;
  204. case 3:
  205. System.exit(0);
  206. break;
  207.  
  208. }
  209.  
  210. }
  211.  
  212. }
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment