Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import javax.swing.*;
  4. import java.lang.*;
  5. public class CreateUserMethod{
  6. public static void main(String[] args) throws Exception {
  7. User LoggedInUser=new User();
  8.  
  9. String[] details= LoginMethod();
  10. double tempBal = Double.parseDouble(details[2]);
  11. LoggedInUser.setEmail(details[0]);
  12. LoggedInUser.setpassword(details[1]);
  13. LoggedInUser.setbalance(tempBal);
  14. System.out.println(LoggedInUser.getbalance());
  15.  
  16.  
  17. }
  18. public static String[] LoginMethod() throws IOException //login method
  19. {
  20. String username, password, filepath;
  21. filepath="Users.txt"; //sets filepath
  22. Scanner x;
  23.  
  24.  
  25.  
  26. username=JOptionPane.showInputDialog(null,"Please Enter Your Username");
  27.  
  28. password=JOptionPane.showInputDialog(null,"Please Enter Your Password");
  29.  
  30. String tempUsername=""; //empty strings
  31. String tempPassword="";
  32. String tempBalance="";
  33.  
  34. boolean found=false;
  35. boolean LoggedIn=false;
  36. while (LoggedIn==false)
  37. {
  38. x= new Scanner(new File(filepath)); // new scanner object
  39. x.useDelimiter("[,\n]"); // breaks strings at ,
  40. while (x.hasNext() && !found) // makes it loop through whole file
  41. {
  42. tempUsername=x.next();
  43. tempPassword=x.next();
  44. tempBalance=x.next();
  45. if (tempUsername.trim().equals(username.trim()) && tempPassword.trim().equals(password.trim()))
  46. {
  47. found=true; // to be used in order to trigger menu possibly
  48.  
  49. }
  50.  
  51. }
  52.  
  53. x.close(); // closes program
  54. if (found==true){
  55. JOptionPane.showMessageDialog (null, "You Have Successfully Logged In as A User");
  56. String num[] = {username,password,tempBalance};
  57. return (num);
  58. }
  59. else
  60. {
  61. int RetryLogin = JOptionPane.showConfirmDialog(
  62. null,
  63. "Would You Like to try login again?",
  64. "Yes No Dialog",
  65. JOptionPane.YES_NO_OPTION);
  66.  
  67.  
  68. if (RetryLogin == JOptionPane.NO_OPTION)
  69. { JOptionPane.showMessageDialog(null, "Thank You For Using My Program");
  70. }
  71. else
  72. { JOptionPane.showMessageDialog(null, "You choose to try again");
  73. LoginMethod();
  74.  
  75. }
  76.  
  77. }
  78. }
  79. return null;
  80. }
  81.  
  82. public static void UserMenu() throws IOException
  83. {
  84. Object[] menuItems = {"View Bookings","View Account Statement","Quit"};
  85. Object selection = JOptionPane.showInputDialog(null,"Options","Menu",1,null,menuItems,menuItems[0]);
  86. if(selection != null)
  87. {
  88. if (selection.equals("View Bookings"))
  89. {
  90. JOptionPane.showMessageDialog(null, "You choose to try again");
  91. UserMenu();
  92. }
  93. else if (selection.equals("View Account Statement"))
  94. {
  95. String Message;
  96. String Bal= LoggedInUser.getbalance();
  97. Message= ("Your Balance is "+Bal+" Euros, Have a Nice day");
  98. UserMenu();
  99. }
  100. else if (selection.equals("Quit"))
  101. {System.exit(1);}
  102. }
  103.  
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement