Advertisement
Guest User

code

a guest
Mar 16th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. package text.game;
  2. import java.util.Scanner;
  3.  
  4. public class TextGame {
  5.  
  6. static Scanner scan = new Scanner(System.in);
  7. static class user extends TextGame {
  8. String username;
  9. int password;
  10. String[] notes;
  11.  
  12. public user(String username, int password) {
  13. this.username = username;
  14. this.password = password;
  15. }
  16.  
  17. }
  18. static user[] userarr = new user[10];
  19. static int a = 0;
  20.  
  21.  
  22. public static void newuser() {
  23. System.out.println("\n\nType the username for this user.");
  24. String usernameA = scan.nextLine();
  25. System.out.println("Username is now " + usernameA + ". is this what you want? type 'yes' to proceed, or 'no' to enter username again.");
  26. if (scan.nextLine().equals("no")) {
  27. newuser();
  28. } else {
  29. System.out.println("\n\n type the password for this user. (numbers only.)");
  30. int passwordA = scan.nextInt();
  31. System.out.println("user is " + usernameA + " and password is " + passwordA + ". creating user.");
  32. userarr[a] = new user(usernameA, passwordA);
  33. System.out.println("user created!");
  34. a += 1;
  35. }
  36. }
  37.  
  38. public static void login() {
  39. System.out.println("which account do you want to log into? type the name of a user, or type 'list' to view the users signed in.");
  40. String ch2 = scan.nextLine();
  41. if (ch2.equals("list")){
  42. for (int i=0;i<a;i++) {System.out.println(userarr[i].username);}
  43. }
  44. }
  45.  
  46.  
  47.  
  48. public static void main(String[] args) {
  49. do {
  50. System.out.println("Welcome to LINCOLN COMP console OS. Type 'new' to create a new user, type 'log' to log in to an existing user, or type 'exit' to leave.\nif you are asked a yes or no question, if you type something other than yes or no, it will default to yes.");
  51. String ch1 = scan.nextLine();
  52. switch (ch1) {
  53. case "new":
  54. if (a==10) {
  55. System.out.println("maximum users have been created. type a username to delete that user, type list to list users, or type back to return.");
  56. String ch3 = scan.nextLine();
  57. if (ch3.equals("list")) {for (int i=0;i<a;i++) {System.out.println(userarr[i].username);}} else if (ch3.equals("back")) {break;} else {
  58. for (int i=0;i<a;i++) {if (System.out.println(userarr[i].username).equals(ch3)){System.out.println("text i will add later");}}
  59. }
  60. }else {
  61. System.out.println("Initializing user creation method:");
  62. newuser();
  63. }
  64. break;
  65. case "log":
  66. login();
  67. break;
  68. case "exit":
  69. System.out.println("Goodbye!");
  70. System.exit(0);
  71. break;
  72. case "debug":
  73. for (int i=0;i<userarr.length;i++) {System.out.println(userarr[i]);}
  74. break;
  75. default:
  76. System.out.println("restarting.");
  77. }
  78.  
  79. } while (true);
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement