Advertisement
Guest User

Test_Sample

a guest
Dec 7th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package test;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class thisClass {
  7.  
  8.  
  9. public static void main(String[] args){
  10.  
  11. Scanner in = new Scanner (System.in);
  12. ArrayList<User> users = new ArrayList<>();
  13.  
  14. User usr1 = new User(1,"Mark21","password1","mpereira@example.com","21/09/1998");
  15. users.add(usr1);
  16.  
  17.  
  18. User usr2 = new User(2,"Cristi01","password2","cAnastasiu@example.com","01/01/1998");
  19. users.add(usr2);
  20.  
  21.  
  22.  
  23. int a = 1;
  24. while (a==1){
  25. System.out.println("\n\nTest Program to create a new User:");
  26. System.out.println("[1]Show list of Registered Usernames.");
  27. System.out.println("[2]Show list of Registered Emails.\n\n");
  28. System.out.println("[3]Test new username.");
  29. System.out.println("[4]Test new email.");
  30. System.out.println("[5]Test password validation.");
  31.  
  32. String input = in.next();
  33.  
  34.  
  35. if (input.equals("1")){
  36. //Show all usernames
  37. for (User eachUser : users){
  38.  
  39. System.out.println(eachUser.getName());
  40.  
  41. }
  42.  
  43. }
  44. if (input.equals("2")){
  45. //Show all emails
  46. for (User eachUser : users){
  47.  
  48. System.out.println(eachUser.getEmail());
  49.  
  50. }
  51. }
  52.  
  53. if (input.equals("3")){
  54. //Input a username, and check if its in the list of recorded usernames
  55. //If its not, the test is successful
  56. System.out.println("Input a new username:");
  57. input = in.next();
  58. System.out.println(input);
  59.  
  60. boolean isValid = false;
  61. for (User eachUser : users){
  62.  
  63. if (input.equals(eachUser.getName())){
  64.  
  65. isValid = true;
  66. System.out.println("This is not a valid username.");
  67.  
  68. }
  69.  
  70.  
  71. }
  72. if (isValid == false){
  73.  
  74. System.out.println("This is a valid username.");
  75. }
  76.  
  77.  
  78. }
  79.  
  80. if (input.equals("4")){
  81. //Input a email, and check if its in the list of recorded emails
  82. //If its not, the test is successful
  83.  
  84. //Never mind the email format (the @ and .com) just explain it in the presentation
  85.  
  86. System.out.println("Input a new email:");
  87. input = in.next();
  88.  
  89.  
  90. boolean isValid = false;
  91. for (User eachUser : users){
  92.  
  93. if (input.equals(eachUser.getEmail())){
  94.  
  95. isValid = true;
  96. System.out.println("This is not a valid email.");
  97.  
  98. }
  99.  
  100.  
  101. }
  102. if (isValid == false){
  103.  
  104. System.out.println("This is a valid email.");
  105. }
  106.  
  107. }
  108. if (input.equals("5")){
  109. System.out.println("Enter a password:");
  110. String input1 = in.next();
  111.  
  112.  
  113. System.out.println("Confirm password:");
  114. String input2 = in.next();
  115.  
  116.  
  117. if (input1.equals(input2)){
  118.  
  119. System.out.println("This is a valid password.");
  120.  
  121.  
  122. }else{
  123.  
  124. System.out.println("Invalid, ensure both inputs are equal.");
  125. }
  126.  
  127.  
  128. }
  129.  
  130.  
  131. }
  132. in.close();
  133.  
  134.  
  135.  
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement