Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.io.*;
  2. public class programma {
  3. public static void main(String[] args) {
  4. String Nome=" ";
  5. String Cognome=" ";
  6. String Indirizzo=" ";
  7. String Telefono=" ";
  8. String nLetto=" ";
  9. int x=0,y=0,z=0;
  10. int indice = 0;
  11.  
  12.  
  13. InputStreamReader input= new InputStreamReader(System.in);
  14. BufferedReader tastiera= new BufferedReader(input);
  15.  
  16. persona [] all=new persona [50];
  17.  
  18. System.out.println("quanti utenti vuoi inserire ? MAX 50 ");
  19. do {
  20. all[indice] = new persona();
  21.  
  22. try
  23. {
  24. nLetto=tastiera.readLine();
  25. x=Integer.parseInt(nLetto);
  26. }
  27. catch(Exception e) {
  28. System.out.println("errore");
  29. return;
  30. }
  31. if(x>50 || x<0) {
  32. System.out.println("errore");
  33. }
  34. }while(x>50 || x<0);
  35. do {
  36. for(int i=0;i<x;i++) {
  37. System.out.println("inserisci il Nome: ");
  38. try {
  39. Nome=tastiera.readLine();
  40. }
  41. catch(Exception e) {
  42.  
  43. System.out.println("Errore");
  44. return;
  45. }
  46. all[indice].SetNome(Nome);
  47.  
  48. System.out.println("inserisci il Cognome: ");
  49. try {
  50. Cognome=tastiera.readLine();
  51.  
  52. }
  53. catch (Exception e) {
  54.  
  55. System.out.println("errore");
  56. return;
  57. }
  58. all[indice].SetCognome(Cognome);
  59.  
  60. System.out.println("inserisci l'Indirizzo: ");
  61. try {
  62. Indirizzo=tastiera.readLine();
  63.  
  64. }
  65. catch (Exception e) {
  66.  
  67. System.out.println("errore");
  68. return;
  69. }
  70. all[indice].SetIndirizzo(Indirizzo);
  71.  
  72. System.out.println("inserisci il Numero di telefono: ");
  73. try {
  74. Telefono=tastiera.readLine();
  75.  
  76. }
  77. catch (Exception e) {
  78. System.out.println("errore");
  79. return;
  80. }
  81. all[indice].SetTelefono(Telefono);
  82.  
  83. System.out.println("voui stampare i dati dell'utante ? 1 per si, qualsiasi altro numero per no");
  84. try {
  85. nLetto=tastiera.readLine();
  86. y=Integer.parseInt(nLetto);
  87. }
  88. catch (Exception e) {
  89. System.out.println("errore");
  90. return;
  91. }
  92. if(y==1) {
  93. all[indice].GetNome();
  94. all[indice].GetCognome();
  95. all[indice].GetIndirizzo();
  96. all[indice].GetTelefono();
  97. }
  98. }
  99. System.out.println("vuoi inserirne un altro ? 1 per si, 2 per no");
  100. try
  101. {
  102. nLetto=tastiera.readLine();
  103. z=Integer.parseInt(nLetto);
  104. }
  105. catch(Exception e) {
  106. System.out.println("errore");
  107. return;
  108. }
  109. indice++;
  110. }while(z==1);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement