Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. public class SkillsDemo3 {
  7. boolean again = true;
  8. int action;
  9.  
  10.  
  11. public static void main(String[] args) throws IOException {
  12.  
  13. //***************************
  14. //Login
  15. //***************************
  16.  
  17. class User {
  18. User (String username, String password)
  19. {
  20. this.username = username;
  21. this.password = password;
  22. }
  23.  
  24. String GetUsername() {return username;}
  25. String GetPassword() {return password;}
  26.  
  27. private String username;
  28. private String password;
  29. }
  30.  
  31.  
  32. String greeting = "Hello";
  33. String username;
  34. String password;
  35.  
  36. // Used to hold the instance of a user who successfully logged in
  37. User loggedInUser = null;
  38.  
  39. // Create an empty list to hold users
  40. List<User> listOfUsers = new ArrayList<>();
  41.  
  42. // Add 3 users to the list
  43. listOfUsers.add(new User("Gerry","spintown"));
  44. listOfUsers.add(new User("Evelyn","poker"));
  45. listOfUsers.add(new User("Joan","bonus"));
  46.  
  47.  
  48. BufferedReader br = new BufferedReader(
  49. new InputStreamReader(System.in));
  50.  
  51.  
  52. System.out.println("*** Welcome to the program ***n");
  53. System.out.println(greeting);
  54.  
  55. System.out.println("Please type your username :");
  56. username = br.readLine();
  57. System.out.println("Please type your password :");
  58. password = br.readLine();
  59.  
  60. for (User user : listOfUsers)
  61. {
  62. if (user.GetUsername().equals(username))
  63. {
  64. if (user.GetPassword().equals(password))
  65. {
  66. loggedInUser = user;
  67.  
  68. // when a user is found, "break" stops iterating through the list
  69. break;
  70. }
  71. }
  72. }
  73.  
  74. // if loggedInUser was changed from null, it was successful
  75. if (loggedInUser != null)
  76. {
  77. System.out.println("User successfully logged in: "+loggedInUser.GetUsername());
  78. }
  79. else
  80. {
  81. System.out.println("Invalid username/password combination");
  82. }
  83.  
  84. //**********************************
  85. //Choice of Games
  86. //**********************************
  87.  
  88.  
  89.  
  90.  
  91. boolean again = true;
  92. int action = 0;
  93.  
  94.  
  95.  
  96. if (action == 1)
  97. {
  98. System.out.println("nYou have chosen to play Rock, Paper, Scissors");
  99. }
  100. else if (action == 2)
  101. {
  102. System.out.println("nYou have chosen to Play pick up sticks");
  103. again = false;
  104. }
  105.  
  106.  
  107.  
  108.  
  109. SkillsDemo3 what = new SkillsDemo3();
  110.  
  111.  
  112. while (what.again)
  113. {
  114. System.out.println("Please type 0 to continue or 1 to stop :");
  115. what.action = Integer.parseInt(br.readLine());
  116. System.out.println("You typed : "+what.action);
  117. what.SkillsDemo3();
  118. }
  119. }
  120.  
  121.  
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement