Guest User

Untitled

a guest
Jul 26th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Services extends Account{
  6.  
  7.  
  8. static int acc_count=0;
  9. static int initial_id=100001;
  10.  
  11. static boolean sender_correct=false, receiver_correct=false,exit=false,l,w;
  12.  
  13. public static void existingCustomer(int cid) throws ClassNotFoundException,SQLException
  14. {
  15.  
  16. Scanner in=new Scanner(System.in);
  17. Class.forName("oracle.jdbc.driver.OracleDriver");
  18. String url="jdbc:oracle:thin:@localhost:1521:xe";//major protocol: minor protocol/Ip address:Portno:SID-> (here loacl :xe)
  19. String userName="System";
  20. String password="desire";
  21. ResultSet rs;
  22. int acc_id=0;
  23. Connection con=DriverManager.getConnection(url,userName,password);
  24.  
  25. Statement s=con.createStatement();
  26.  
  27. String query="select * from bank where id="+cid;
  28.  
  29. rs=s.executeQuery(query);
  30. if(rs.next())
  31. {
  32.  
  33. int ac=rs.getInt("status");
  34. if(ac!=1)
  35. {
  36. System.out.println("Services with this account is temporarly suspended..");
  37. return;
  38. }
  39.  
  40. System.out.println("Enter password:");
  41. String pass=in.next();
  42. String upass=rs.getString("password");
  43. if(pass.equals(upass))
  44. {
  45. acc_id=rs.getInt(1);
  46. }
  47. else
  48. {
  49. System.out.println("Invalid password");
  50. return;
  51. }
  52. }
  53. else
  54. {
  55. System.out.println("No Account with such account");
  56. return;
  57. }
  58.  
  59. Account sender=new Account();
  60. Account receiver=new Account();
  61. String type;
  62. double amt;
  63. boolean flag=false;
  64. do
  65. {
  66. System.out.println("1.Deposit Money\n2.Withdraw Money\n3.Fund Transfer\n4.Deactivate Account\n5.Account Informatoin\n6.Exit\n");
  67. System.out.println("Enter your choice:");
  68. int input=in.nextInt();
  69.  
  70. switch(input)
  71. {
  72.  
  73.  
  74. case 1:
  75. if(acc_id!=0)
  76. {
  77.  
  78. System.out.println("Enter the ammount to deposite;");
  79. double deposite_amt=in.nextDouble();
  80. try{
  81.  
  82. l=Account.addBalance(acc_id,deposite_amt);
  83. }catch (Exception e)
  84. {
  85. e.printStackTrace();
  86. }
  87.  
  88. if(l)
  89. System.out.println("Ammount added sucessfully!");
  90. }
  91. break;
  92.  
  93. case 2: if(acc_id!=0)
  94. {
  95. System.out.println("Enter the ammount to withdraw;");
  96. double withdraw_amt=in.nextDouble();
  97. try
  98. {
  99. w=Account.withdrawBalance(acc_id,withdraw_amt);
  100. }catch(Exception e)
  101. {
  102. e.printStackTrace();
  103. }
  104. if(w)
  105. System.out.println("Ammount withdrawn sucessfully!");
  106. }
  107. break;
  108.  
  109.  
  110.  
  111. case 3: if(acc_id!=0)
  112. {
  113. System.out.println("Enter your Receiver id:");
  114. int receiver_id=in.nextInt();
  115.  
  116. String fquery="select id from bank where id="+receiver_id;
  117. ResultSet rs1=s.executeQuery(fquery);
  118. if(rs1.next())
  119. {
  120. System.out.println("Enter the ammount to transfer");
  121. double transfer_amt=in.nextDouble();
  122. try{
  123. if(Account.checkBalance(acc_id)>transfer_amt)
  124. {
  125. Account.addBalance(rs1.getInt(1),transfer_amt);
  126. Account.withdrawBalance(acc_id,transfer_amt);
  127.  
  128. }
  129.  
  130. else
  131. {
  132. System.out.println("Insufficent Balance");
  133. }
  134. }catch(Exception e)
  135. {
  136. e.printStackTrace();
  137. }
  138.  
  139. }
  140.  
  141.  
  142. else
  143. {
  144. System.out.println("No Account with such id");
  145. }
  146. }
  147.  
  148. break;
  149. case 4:
  150. if(acc_id!=0)
  151. try{
  152. Account.deactivate(acc_id);
  153. }catch(Exception e)
  154. {
  155. e.printStackTrace();
  156. }
  157. break;
  158.  
  159.  
  160. case 5:
  161. try{
  162. Account.showAccountInfo(acc_id);
  163. }catch (Exception e) {
  164. e.printStackTrace();
  165. }
  166.  
  167. break;
  168. case 6:exit=true;
  169. break;
  170.  
  171. }
  172.  
  173.  
  174.  
  175.  
  176. }while(!exit);
  177.  
  178. }
  179.  
  180. public static boolean newCustomer() throws Exception
  181. {
  182.  
  183. String type=null;
  184. Scanner in=new Scanner(System.in);
  185. double amt=0;
  186. int acc_id=0;
  187. int ini_id=10000;
  188. boolean valid=true;
  189. System.out.println("Enter the name of holder:");
  190.  
  191. String name=in.nextLine();
  192. System.out.println("Select the account type\n1.saving\n2.current:");
  193. int a_type=in.nextInt();
  194. if(a_type==1)
  195. {
  196. type="saving";
  197. System.out.println("Enter initial Balance(minimum balance:1000)");
  198. amt=in.nextDouble();
  199. while(amt<1000)
  200. {
  201. System.out.println("unacceptable, Enter more than 1000");
  202. amt=in.nextDouble();
  203. }
  204.  
  205.  
  206. }
  207. else if(a_type==2)
  208. {
  209. type="current";
  210. System.out.println("Enter initial Balance(minimum balance:10000)");
  211. amt=in.nextDouble();
  212. while(amt<10000)
  213. {
  214. System.out.println("unacceptable, Enter more than 10000");
  215. amt=in.nextDouble();
  216. }
  217. }
  218. else
  219. {
  220. System.out.println("Please Retry with valid account type");
  221. return false;
  222. }
  223. System.out.println("Would you like Set your own custom id?");
  224. System.out.println("1.No,Let Bank assign one for me\n2.Yes,I want Custom Id");
  225. int temp=in.nextInt();
  226. if(temp==1)
  227. {
  228. while(Account.checkId(ini_id))
  229. {
  230. ini_id++;
  231. }
  232. acc_id=ini_id;
  233. }
  234. else if(temp==2)
  235. {
  236. while(true)
  237. {
  238. System.out.println("Enter the id you want which should contain only numerics (0-9)");
  239. int id=in.nextInt();
  240. try{
  241. valid=Account.checkId(id);
  242. }
  243. catch(Exception e){
  244. e.printStackTrace();
  245. }
  246. if(valid)
  247. {
  248. System.out.println("Retry!! Id already Exist");
  249.  
  250. }
  251. else
  252. {
  253. acc_id=id;
  254. break;
  255. }
  256. }
  257. }
  258. else
  259. {
  260. System.out.println("Re-Enter proper details");
  261. }
  262. System.out.println("Enter password for your account\n");
  263. String password=in.next();
  264. String query1="insert into bank values("+acc_id+",'"+name+"',"+"'"+type+"',"+amt+",1,'"+password+"')";
  265.  
  266. Jdbc myjdbc=new Jdbc();
  267. int st=myjdbc.s.executeUpdate(query1);
  268. if(st==1)
  269. {
  270. System.out.println("Accout Added successfuly");
  271. try{
  272. Account.showAccountInfo(acc_id);
  273. }catch (Exception e) {
  274. e.printStackTrace();
  275. }
  276.  
  277. }
  278. else
  279. {
  280. System.out.println("Account cannot be added");
  281. }
  282. return true;
  283. }
  284.  
  285.  
  286. }
Add Comment
Please, Sign In to add comment