Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Customer
  4. {
  5. public int balance;
  6. public String username;
  7. public int pinNumber;
  8.  
  9. Customer()
  10. {
  11.  
  12. }
  13.  
  14. Customer(int b, String uName, int pin)
  15. {
  16. b = balance;
  17. username = uName;
  18. pinNumber = pin;
  19. }
  20.  
  21.  
  22. }
  23.  
  24.  
  25. class Main
  26. {
  27. public static void main(String[] args)
  28. {
  29. Scanner s = new Scanner(System.in);
  30. int loggedIn = 0;
  31. Customer loggedInCustomer = new Customer();
  32. Customer[] customers = new Customer[5];
  33. customers[0] = new Customer(1000, "Mike", 1234);
  34. customers[1] = new Customer(80000, "Mashraful", 1234);
  35. customers[2] = new Customer();
  36. customers[3] = new Customer();
  37. customers[4] = new Customer();
  38. System.out.println("Please enter your username.");
  39.  
  40. //String input = s.nextLine();
  41.  
  42. while(loggedIn == 0)
  43. {
  44. String input = s.nextLine();
  45. int pin_input = 0;
  46. int i;
  47.  
  48. for(i = 0; i < 4; i++)
  49. {
  50. if(input.equals(customers[i].username))
  51. {
  52. System.out.println("Username found. Please enter your PIN.");
  53. pin_input = s.nextInt();
  54. if(pin_input == customers[i].pinNumber)
  55. {
  56. System.out.println("Successfully logged in.");
  57. loggedInCustomer = customers[i];
  58. loggedIn = 1;
  59. ///break;
  60. }
  61.  
  62. }
  63. }
  64. if(!input.equals(customers[i].username) && loggedIn == 0)
  65. {
  66. System.out.println("Incorrect username. Please try again.");
  67. break;
  68. }
  69. if(pin_input != customers[i].pinNumber && loggedIn == 0)
  70. {
  71. System.out.println("Incorrect pin. Login attempt has been reset.");
  72. break;
  73. }
  74. }
  75.  
  76. if(loggedIn == 1)
  77. {
  78. System.out.println("Welcome " + loggedInCustomer.username + ". Your balance is: " + loggedInCustomer.balance);
  79. String input = s.nextLine();
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement