Advertisement
Guest User

fdsafkekjf skjd

a guest
Oct 24th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.lang.*;
  4. import javax.swing.JOptionPane;
  5. public class login {
  6. public static void main (String [] args) throws IOException {
  7. String usernameEntered="";
  8. String passwordEntered="";
  9.  
  10.  
  11. ArrayList<String> user = new ArrayList<String>();
  12. ArrayList<String> pass = new ArrayList<String>();
  13. ArrayList<String> first = new ArrayList<String>();
  14. ArrayList<String> last = new ArrayList<String>();
  15. File file = new File("UsersInfo.txt");
  16. Scanner inputFile = new Scanner(file);
  17. String fName="";
  18. String lName="";
  19. int generalPos=0;
  20. File quest = new File("TestBank.txt");
  21. File answ = new File("AnswBank.txt");
  22. Scanner inputFile2 = new Scanner(quest);
  23. Scanner inputFile3 = new Scanner(answ);
  24. Scanner keyboard = new Scanner(System.in);
  25. ArrayList<String> questions = new ArrayList<String>();
  26. ArrayList<String> answers = new ArrayList<String>();
  27.  
  28. int tries = 4;
  29. boolean usernameFlag = false;
  30. boolean passwordFlag = false;
  31. while (inputFile.hasNext())
  32. {
  33. String str = inputFile.nextLine();
  34. String usernameList = str.split("\t")[0];
  35. String passwordList = str.split("\t") [1];
  36. String firstName = str.split("\t") [2];
  37. String lastName = str.split("\t") [3];
  38. user.add(usernameList);
  39. pass.add(passwordList);
  40. first.add(firstName);
  41. last.add(lastName);
  42. int d;
  43. }
  44.  
  45. while(tries >= 1){
  46. {
  47. usernameEntered = JOptionPane.showInputDialog("Enter your username");
  48.  
  49. passwordEntered = JOptionPane.showInputDialog("Enter your password");
  50.  
  51. generalPos = user.indexOf(usernameEntered);
  52. if(usernameEntered.equals(user.get(generalPos)) && (passwordEntered.equals(pass.get(generalPos))))
  53. { JOptionPane.showMessageDialog(null, "Starting Quiz...");
  54. tries = -1;
  55. }
  56.  
  57. else
  58. {
  59. JOptionPane.showMessageDialog(null, "Error, you have " + (tries - 1) + " tries left.");
  60. tries--;
  61. continue;
  62. }
  63. }
  64.  
  65. if( tries == 0)
  66. System.exit(0);
  67.  
  68.  
  69. }
  70.  
  71.  
  72. fName=first.get(generalPos);
  73. lName=last.get(generalPos);
  74.  
  75.  
  76. JOptionPane.showMessageDialog(null, "Welcome " + fName + " " + lName + "!");
  77.  
  78.  
  79.  
  80. while(inputFile2.hasNextLine())
  81. questions.add(inputFile2.nextLine());
  82. while(inputFile3.hasNextLine())
  83. answers.add(inputFile3.nextLine());
  84. Random rand = new Random();
  85. String userAnswer;
  86. int counter=0;
  87.  
  88.  
  89. double begin=System.currentTimeMillis();
  90.  
  91. for(int i=0; i<10; i++){
  92. int x = rand.nextInt(questions.size());
  93. //JOptionPane.showMessageDialog(null,questions.get(x));
  94. userAnswer=JOptionPane.showInputDialog(questions.get(x) + " Enter your answer. (True or False)");
  95.  
  96. if((userAnswer.equals("t"))||(userAnswer.equals("T")))
  97. userAnswer="true";
  98. if((userAnswer.equals("f"))||(userAnswer.equals("F")))
  99. userAnswer="false";
  100. userAnswer=userAnswer.toUpperCase();
  101. if(((userAnswer.equals("TRUE"))||(userAnswer.equals("FALSE"))))
  102. {
  103. if(userAnswer.toUpperCase().equals(answers.get(x).toUpperCase())){
  104. JOptionPane.showMessageDialog(null,"Correct!");
  105. counter++;}
  106. else
  107. JOptionPane.showMessageDialog(null,"Incorrect!");
  108. }
  109.  
  110.  
  111. else{
  112. JOptionPane.showMessageDialog(null,"Please enter a valid answer.");
  113. JOptionPane.showMessageDialog(null,questions.get(x));
  114. userAnswer=JOptionPane.showInputDialog("Enter your answer. (True or False)");
  115. if((userAnswer.equals("t"))||(userAnswer.equals("T")))
  116. userAnswer="true";
  117. if((userAnswer.equals("f"))||(userAnswer.equals("F")))
  118. userAnswer="false";
  119. userAnswer=userAnswer.toUpperCase();
  120. if(userAnswer.toUpperCase().equals(answers.get(x).toUpperCase())){
  121. JOptionPane.showMessageDialog(null,"Correct!");
  122. counter++;}
  123. else
  124. JOptionPane.showMessageDialog(null,"Incorrect!");
  125.  
  126.  
  127. }
  128. }
  129. double end=System.currentTimeMillis()-begin;
  130. end=end/1000.0;
  131. JOptionPane.showMessageDialog(null,"Name: " + fName + "" + lName + "\nIt took you " + String.format("%.0f",end) + " seconds to complete the test.\nScore: " + counter + " out of 10 correct.");
  132.  
  133.  
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement