Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. ArrayList <UserInfo> InfoList = new ArrayList<UserInfo> ();
  2.  
  3. public void userInternalDatabase (UserInfo info)
  4. {
  5. this.user = info.user;
  6. this.pass = info.pass;
  7. this.secretCode = info.secretCode;
  8. }
  9. public void addUser(String i, String j, String k)
  10. {
  11. UserInfo newUser = new UserInfo();
  12. newUser.user = i;
  13. newUser.pass = j;
  14. newUser.secretCode = k;
  15. InfoList.add(newUser);
  16. }
  17.  
  18. public Object findUsername(String a)
  19. {
  20. for (int i=0; i <InfoList.size(); i++)
  21. {
  22. if (InfoList.get(i).user.equals(a))
  23. {
  24. return "This user already exists in our database.";
  25. }
  26. }
  27. return "NÃO EXISTE ESSE UTILIZADOR.";
  28. }
  29. }
  30.  
  31. class DadosGuardados
  32. {
  33.  
  34. private static int lerNumero(Scanner kb, String mensagem, String mensagemErro)
  35. {
  36. while (true)
  37. {
  38. System.out.println(mensagem);
  39. try
  40. {
  41. return Integer.parseInt(kb.nextLine());
  42. }
  43. catch (NumberFormatException e)
  44. {
  45. System.out.println(mensagemErro);
  46. }
  47. }
  48. }
  49.  
  50. private static boolean lerSimNao(Scanner kb, String mensagem, String mensagemErro)
  51. {
  52. while (true)
  53. {
  54. System.out.println(mensagem);
  55. String x = kb.nextLine();
  56. if (x.equalsIgnoreCase("S")) return true;
  57. if (x.equalsIgnoreCase("N")) return false;
  58. System.out.println(mensagemErro);
  59. }
  60. }
  61. public static void main(String[] args)
  62. {
  63. Scanner kb = new Scanner(System.in);
  64.  
  65. System.out.println("Bem-vindo, utilizador.");
  66. boolean maisRecarga = true;
  67. while (maisRecarga)
  68. {
  69. int recarga = lerNumero(kb, "Introduza o número da recarga: ", "Isso que você digitou não era um número. Por favor, tente novamente.");
  70. System.out.println("Você digitou " + recarga + ".");
  71. maisRecarga = lerSimNao(kb, "Tem mais recarga para registar?nResponda `S´ para continuar ou `N´ para terminar: ", "Era para você responder S ou N! Por favor, tente novamente.");
  72.  
  73. }
  74. System.out.println("Obrigado, até o próximo registro.");
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement