Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. import java.io.*;
  2. public class VenditeDegliAagenti {
  3. public static void main(String[]args)throws IOException
  4. {
  5. int NumeroAgenti = LeggiNumeriAgenti();
  6. int NumeroVendite = LeggiNumeroDiVenditePerAgenteCorrente();
  7. MediaMassimaMinimaImportoMassimoMinimo(NumeroAgenti);
  8. }
  9. public static int LeggiNumeriAgenti()throws IOException
  10. {
  11. //Leggo un numero in ingresso
  12. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  13. System.out.println("Inserisci il numero degli agenti");
  14. String line = input.readLine();
  15. //Verifico se non è negativo o se ha valore 0
  16. int NumeroAgenti = Integer.parseInt(line);
  17. if (NumeroAgenti<=0)
  18. {
  19. System.out.println("Inserisci un numero maggiore di 0");
  20. line = input.readLine();
  21. NumeroAgenti = Integer.parseInt(line);
  22. }
  23. return NumeroAgenti;
  24. }
  25. public static int LeggiNumeroDiVenditePerAgenteCorrente()throws IOException
  26. {
  27. //Leggo un numero in ingresso
  28. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  29. System.out.println("Inserisci il numero delle vendite per l'agente corrente");
  30. String line = input.readLine();
  31. //Verifico se non è negativo o se ha valore 0
  32. int NumeroVendite = Integer.parseInt(line);
  33. if (NumeroVendite<=0)
  34. {
  35. System.out.println("Inserisci un numero maggiore di 0");
  36. line = input.readLine();
  37. NumeroVendite = Integer.parseInt(line);
  38. }
  39. return NumeroVendite;
  40. }
  41. public static int ChiediImportoDiUnaVendita()throws IOException
  42. {
  43. //Leggo un numero in ingresso
  44. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  45. System.out.println("Inserisci l'importo");
  46. String line = input.readLine();
  47. //Verifico se non è negativo o se ha valore 0
  48. int Importo = Integer.parseInt(line);
  49. if (Importo<=0)
  50. {
  51. System.out.println("Inserisci un numero maggiore di 0");
  52. line = input.readLine();
  53. Importo = Integer.parseInt(line);
  54. }
  55. return Importo;
  56. }
  57. public static void MediaMassimaMinimaImportoMassimoMinimo(int NumeroAgenti)throws IOException
  58. {
  59. double Massimo = 0;
  60. double Minimo = 99999;
  61. int SommaImportiAgente = 0;
  62. double SommaImportiAgenti = 0;
  63. double SommaMedieAgenti = 0;
  64. double MediaAgente = 0;
  65. double MediaTotale = 0;
  66. double MediaMinima = 9999;
  67. double MediaMassima = 0;
  68.  
  69. for(int i = 0;i<NumeroAgenti;i++)
  70. {
  71. SommaImportiAgente = 0;
  72. int NumeroVendite = LeggiNumeroDiVenditePerAgenteCorrente();
  73. for(int z = 0; z<NumeroVendite;z++)
  74. {
  75. //Leggo il voto richiamando la funzione e poi controllo se è un voto alto o basso
  76. double Importo = ChiediImportoDiUnaVendita();
  77. SommaImportiAgente += Importo;
  78. if(Importo>Massimo)
  79. Massimo=Importo;
  80. if (Importo<Minimo)
  81. Minimo=Importo;
  82.  
  83. }
  84. MediaAgente = SommaImportiAgente/NumeroVendite;
  85. SommaMedieAgenti += MediaAgente;
  86. System.out.println("La media di questo agente e' " + MediaAgente);
  87.  
  88. //Una volta calcolata la media di un singolo agente verifico se è una media alta o bassa
  89.  
  90. if(MediaAgente>MediaMassima)
  91. {
  92. MediaMassima=MediaAgente;
  93. }
  94. if (MediaAgente<MediaMinima)
  95. {
  96. MediaMinima = MediaAgente;
  97. }
  98.  
  99. }
  100. MediaTotale = SommaMedieAgenti/NumeroAgenti;
  101. Stampa(MediaTotale, Minimo, Massimo, MediaMinima, MediaMassima);
  102. }
  103. public static void Stampa(double MediaTotale,double Minimo,double Massimo,double MediaMinima,double MediaMassima)throws IOException
  104. {
  105. //Mi occupo di stampare i risultati ottenuti dalle altre funzioni
  106. System.out.println("La media totale e': " + MediaTotale);
  107. System.out.println("La media minima e' : "+ MediaMinima);
  108. System.out.println("La media massima e': "+ MediaMassima);
  109. System.out.println("Il voto piu' basso e': "+ Minimo);
  110. System.out.println("Il voto piu' alto e': "+ Massimo);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement