Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.File;
  6. import java.io.FileWriter;
  7. import java.io.FileNotFoundException;
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. import java.io.*;
  11. //import java.security.*;
  12. import java.util.*;
  13.  
  14. public class Program_logreg {
  15.  
  16. public static Scanner userInput1 = new Scanner(System.in); //holds string
  17. public static Scanner userInput2 = new Scanner(System.in); //holds char
  18.  
  19.  
  20. public static void main(String[] arg) throws IOException{
  21. System.out.println("Please log in first\n");
  22. System.out.println("\n-----");
  23. System.out.println("LOGIN");
  24. System.out.println("-----");
  25.  
  26.  
  27. Employee temp = null;
  28.  
  29. while(true){
  30.  
  31. System.out.print("Username: ");
  32. String username = userInput1.nextLine();
  33.  
  34. System.out.print("Password: ");
  35. String password = userInput1.nextLine();
  36.  
  37. temp = ReadFile.getEmployeeInfo(username);
  38.  
  39. if(temp == null){
  40. System.out.println("\nThis username does not exist!\n");
  41. continue;
  42. }
  43.  
  44. if(!temp.getPassword().equals(password)){
  45. System.out.println("\nThis password is not correct!\n");
  46. continue;
  47. }
  48.  
  49. //tempUser.setLoggedIn(true);
  50.  
  51. if(temp != null) {
  52. System.out.println("\nWelcome!\n");
  53. break;
  54. }
  55. }
  56.  
  57. if(temp.getRole().equals("Manager")){
  58. while (true){
  59. System.out.println("\nDo you want to register new waiter? Y or N? ");
  60. char choice = userInput2.next().charAt(0);
  61. if(choice == 'Y'){
  62. Manager.registerWaiter();
  63.  
  64. }else if (choice != 'Y'& choice != 'N'){
  65. System.out.println("Not a valid option");
  66. }else{
  67. break;
  68. }
  69. }
  70. while (true){
  71. System.out.println("\nDo you want to de-register new waiter? Y or N? ");
  72. char choice = userInput2.next().charAt(0);
  73. if(choice == 'Y'){
  74.  
  75. Employee remove = null;
  76. System.out.println("\nWhich waiter (Username) do you want to de-register?");
  77. String username = userInput1.nextLine();
  78.  
  79. //remove = ReadFile.getEmployeeInfo(username);
  80.  
  81. try{
  82. BufferedReader br= new BufferedReader(new FileReader("Employee.txt"));
  83. String sCurrentLine;
  84. String[] uCurrentLine = new String[5];
  85. File f = new File("tempFile.txt");
  86. PrintWriter wr = new PrintWriter(new BufferedWriter (new FileWriter(f, true)));
  87. int idCount = -1;
  88. while((sCurrentLine = br.readLine()) != null){
  89. uCurrentLine = sCurrentLine.split(";");
  90. //System.out.println(uCurrentLine[4]);
  91. if (uCurrentLine.length == 5){
  92. if(!uCurrentLine[1].toLowerCase().equals(username.toLowerCase())){
  93. remove = new Employee(Integer.parseInt(uCurrentLine[0]),
  94. uCurrentLine[1],
  95. uCurrentLine[2],
  96. uCurrentLine[3],
  97. uCurrentLine[4]
  98. );
  99. idCount++;
  100. String tempLine = idCount +";"+ remove.getUsername() +";"+ remove.getName() +";"+ remove.getPassword() + ";" + remove.getRole();
  101. wr.println(tempLine);
  102. }
  103. }
  104.  
  105. }
  106. wr.close();
  107. br.close();
  108.  
  109. boolean success = (new File("Employee.txt")).delete();
  110. if (success) {
  111. File fileNew = new File("Employee.txt");
  112. f.renameTo(fileNew);
  113. //System.out.println("The file has been xรณa");
  114. }
  115.  
  116. }
  117. catch (IOException e) {
  118. e.printStackTrace();
  119. }
  120. }else if (choice != 'Y'& choice != 'N'){
  121. System.out.println("Not a valid option");
  122. }else{
  123. break;
  124. }
  125.  
  126. }
  127. //System.out.println("\nDo you want to read the report? Y or N? ");
  128.  
  129. }
  130.  
  131. }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement