943,718 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 26384
  • Java RSS
May 1st, 2008
1

ATM program

Expand Post »
I already wrote an ATM program which did store only three account number, password and balance but now I want to get these information from a file which would be read to the program and by entering the information the program should search the file and find the line that fit the information that I entered first for account number then for password and if all match one of 50000 account in the file show the balance of that account and also if I need to deposit or withdraw from one of the account it would save the new balance and next time if I sign in with that account it would show me the new balance which I changed by adding deposit to it or withdraw mony from it!
I know that some how my program reads the file and copy it to another file and also in another method erase the copy file that ?I have and should replace it with the new information(balance) but I don't know how to do it! would someone please help me and walk me through it.
This is the one that I wrote with 3 accounts information stored in the program itself:
Please please someone help me as soon as possible!
Java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;//name of the package(library)that includes the * class
  2.  
  3. public class ATM{//name of the program
  4.  
  5. public static Scanner kbd;//Scanner kbd function
  6. public static void main(String[] args) {// the main program with the word void doesn't let anything out
  7. String userAnswer = null;//declaring the string
  8. Scanner kbd = new Scanner(System.in); // declaring the function
  9. double accountbalance = 0, depositamount = 0, withdrawalbalance= 0;//declaring the variables, accountbalance, depositamount, withdrawalbalance, as double
  10. String acctNum,pwd;//declaring acctNum, pwd as string
  11. String acctres;//declaring acctres as string
  12. int counter=0;//declaring counter as int
  13. int Choice;//declaring Choice as int
  14. do//gives the do-while loop the condition to repeat the statement
  15. {
  16. System.out.println("Please enter your account number: ");//gives the system command to print
  17.  
  18. acctNum = kbd.nextLine();//getting the inputs and allocating
  19. System.out.println("Please enter your account password: ");//gives the system command to print
  20. pwd = kbd.nextLine();//getting the inputs and allocating
  21.  
  22. acctres=checkID(acctNum,pwd);//Initializing acctres
  23.  
  24. if(!acctres.equals("error"))// checking for the situation of the acctres variable for error
  25. {
  26. accountbalance = Double.parseDouble(acctres);//Initializing accountbalance
  27.  
  28. do//gives the do-while loop the condition to repeat the statement
  29. {
  30. Choice = Menu();//Initializing Menu()
  31. System.out.println(Choice);//gives the system command to print
  32. if (Choice == 1)//checking for input 1
  33. {
  34. System.out.println("Your Balance is: " + accountbalance + "$");//gives the system command to print
  35. }
  36. else if (Choice == 2)//checking for input 2
  37. {
  38. System.out.println("How much would you like to deposit to your account? ");//gives the system command to print
  39. depositamount=kbd.nextDouble();//getting the inputs and allocating
  40. double calculatebalance = Deposit(accountbalance, depositamount);//Initializing calculatebalance
  41. System.out.println("Your Balance with your Deposit now is: " + calculatebalance + "$");//gives the system command to print
  42. }
  43. else if (Choice == 3)//checking for input 3
  44. {
  45. System.out.println("How much would you like to withdrawal from your account? ");//gives the system command to print
  46. withdrawalbalance=kbd.nextDouble();//getting the inputs and allocating
  47. double calculatebalance1 = Withdraw(accountbalance, withdrawalbalance);//Initializing calculatebalance1
  48. System.out.println("You Balance now is: " + calculatebalance1 + "$");//gives the system command to print
  49. }
  50. else// checking for the other inputs except the ones which were mentioned
  51. {
  52. System.out.println("Do you want to Log Out? (Y or N) ");//gives the system command to print
  53. userAnswer=kbd.next();//getting the inputs and allocating
  54. userAnswer=userAnswer.toUpperCase();//to ignore the upper case or lower case input and count them as the same
  55. if (userAnswer.equals("Y"))//checking for the situation of userAnswer for being equal Y which means yes
  56. {
  57. System.out.println("You are now logged out!");//gives the system command to print
  58. System.exit(0);// gives command for the if statement
  59. }
  60.  
  61. }
  62. }while ((Choice <=4)|| (userAnswer.equals("N")));//Checking input N
  63.  
  64. }
  65. else// checking for other input except the ones that already were mentioned
  66. {
  67. System.out.println("Error");//gives the system command to print
  68. counter++;//Increasing the counter by 1
  69. System.out.println(counter);//gives the system command to print
  70. }
  71.  
  72. }while(counter<3);//checking for the counter to be less than 3 or not
  73.  
  74. System.out.println("You have exceeded the required amount of times.");//gives the system command to print
  75. }
  76.  
  77. public static String checkID(String acctNum, String pwd)//separating the part from the main program as a new function in the main function
  78. {
  79. String result = "error";//declaring the result as string
  80. // Strings a, b, and c contain the valid account numbers and passwords.
  81. // For each string, the account number is listed first, followed by
  82. // a space, followed by the password for the account, followed by a space,
  83. // followed by the current balance.
  84. String a = "44567-5 mypassword 520.36";//declaring string a which id equal 44567-5 mypassword 520.36 in this function
  85. String b = "12345-6 anotherpassword 48.20";//declaring string b which id equal 12345-6 anotherpassword 48.20 in this function
  86. String c = "54321-0 betterpassword 96.74";//declaring string c which id equal 54321-0 betterpassword 96.74 in this function
  87. String d=a.substring(0,7);//declaring string d in this function
  88. String e=a.substring(8,18);//declaring string e in this function
  89. String eres=a.substring(19);//declaring string eres in this function
  90. String f=b.substring(0,7);//declaring string f in this function
  91. String g=b.substring(8,23);//declaring string g in this function
  92. String gres=b.substring(24);//declaring string gres in this function
  93. String h=c.substring(0,7);//declaring string h in this function
  94. String i=c.substring(8,22);//declaring string i in this function
  95. String ires=c.substring(23);//declaring string ires in this function
  96. if(acctNum.equals(d) && pwd.equals(e))//checking for account number and password
  97. {
  98. result=eres;//gives commands for the if statement
  99. }
  100. else if(acctNum.equals(f) && pwd.equals(g))//checking for account number and password
  101. {
  102. result=gres;//gives commands for the if statement
  103. }
  104. else if(acctNum.equals(h) && pwd.equals(i))//checking for account number and password
  105. {
  106. result=ires;//gives commands for the if statement
  107. }
  108. return result;//to get data out of the function and takes the value with it only once
  109. }
  110.  
  111. public static double Displaybalance1(double accountbalance)//separating the part from the main program as a new function in the main function
  112. {
  113.  
  114. return accountbalance;//to get data out of the function and takes the value with it only once
  115. }
  116.  
  117. public static double Deposit(double accountbalance, double depositamount)//separating the part from the main program as a new function in the main function
  118. {
  119. return accountbalance+ depositamount;//to get data out of the function and takes the value with it only once
  120. }
  121.  
  122. public static double Withdraw(double accountbalance, double withdrawalbalance)//separating the part from the main program as a new function in the main function
  123. {
  124. double newbalance1 = 0;//declaring the variables, newbalance1, as double
  125. if (withdrawalbalance<=accountbalance)//checking the condition in the parentheses(if withdrawalamount is less than or equal the accontbalance or not)
  126. {
  127. newbalance1 = accountbalance - withdrawalbalance;//gives the system command to print the calculated amount
  128. }
  129. else if (withdrawalbalance>accountbalance)//checking the condition in the parentheses(if withdrawalamount is more than the accontbalance or not)
  130. {
  131. newbalance1 = accountbalance;//declaring the newbalance1 as previous accountbalance without change
  132. System.out.println("error, that is impossible! your account balance still is: " + newbalance1);//gives the system command to print the accountbalance without changing it
  133. }
  134. return newbalance1;//to get data out of the function and takes the value with it only once
  135. }
  136. public static int Menu()//separating the part from the main program as a new function in the main function
  137.  
  138. {
  139. int Option ;//declaring the variables, Size, as int
  140. do//gives the do-while loop the condition to repeat the statement
  141. {
  142. Scanner kbd1 = new Scanner(System.in);// declaring the function
  143. System.out.println("1. Display Balance ");//gives the system command to print
  144. System.out.println("2. Deposit ");//gives the system command to print
  145. System.out.println("3. Withdraw ");//gives the system command to print
  146. System.out.println("4. Log Out ");//gives the system command to print
  147. System.out.println("Enter your option");//gives the system command to print
  148. Option = kbd1.nextInt();//getting the inputs and allocating
  149. if ((Option<=0)&&(Option > 4))//checking for the statement in parentheses(Smaller or equal 0 or bigger than 4 inputs)
  150. {
  151. System.out.println("Error! Choose again: ");//gives the system command to print
  152. }
  153. }while ((Option<=0)&&(Option > 4));//gives the while loop the condition to stop the repeating statement
  154.  
  155. return Option;//to get data out of the function and takes the value with it only once
  156. }
  157. }
Last edited by ~s.o.s~; Dec 9th, 2008 at 11:02 pm. Reason: Added code tags, learn to use them.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
john44 is offline Offline
1 posts
since May 2008
Dec 9th, 2008
-1

Re: ATM program

please write you code inside the BB code required cause some of us can't understand.. tnx
Reputation Points: 9
Solved Threads: 1
Junior Poster
ezkonekgal is offline Offline
109 posts
since Sep 2008
Dec 15th, 2008
0

Re: ATM program

Do you have one table for "account"/"deposit"/"withdraw" "balance"/"last_update" ? Every time when any account has any transaction you will save it into table, so next time you log in you will check there is any "new" balance from the table first. If yes, you will show it.


Albert
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
May 11th, 2010
-2

ATM

pano po gawin sa java yung kunyare nag-enter ako nang number tapos ang lalabas asteris(*)
Reputation Points: 7
Solved Threads: 0
Newbie Poster
itovin is offline Offline
1 posts
since May 2010
May 11th, 2010
0
Re: ATM program
Click to Expand / Collapse  Quote originally posted by itovin ...
pano po gawin sa java yung kunyare nag-enter ako nang number tapos ang lalabas asteris(*)
Start a new thread.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Oct 18th, 2010
-1
Re: ATM program
how to program the atm
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WINDGUARD is offline Offline
1 posts
since Oct 2010
Nov 15th, 2010
-1
Re: ATM program
Hi, can u add a biometric authentication code to this? please help me out. need it for my project. you can send it to my box. <EMAIL SNIPPED>
Last edited by peter_budo; Nov 16th, 2010 at 4:57 am. Reason: Keep It Organized - Do not ask anyone (member or moderator) for help by email or PM
Reputation Points: 9
Solved Threads: 0
Newbie Poster
walexy4real is offline Offline
1 posts
since Nov 2010
Nov 15th, 2010
0
Re: ATM program
@walexy: No, you're just going to have to do your own work.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,760 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Threading book
Next Thread in Java Forum Timeline: Help with practice problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC