Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class VenditeDegliAagenti {
- public static void main(String[]args)throws IOException
- {
- int NumeroAgenti = LeggiNumeriAgenti();
- int NumeroVendite = LeggiNumeroDiVenditePerAgenteCorrente();
- MediaMassimaMinimaImportoMassimoMinimo(NumeroAgenti);
- }
- public static int LeggiNumeriAgenti()throws IOException
- {
- //Leggo un numero in ingresso
- BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Inserisci il numero degli agenti");
- String line = input.readLine();
- //Verifico se non è negativo o se ha valore 0
- int NumeroAgenti = Integer.parseInt(line);
- if (NumeroAgenti<=0)
- {
- System.out.println("Inserisci un numero maggiore di 0");
- line = input.readLine();
- NumeroAgenti = Integer.parseInt(line);
- }
- return NumeroAgenti;
- }
- public static int LeggiNumeroDiVenditePerAgenteCorrente()throws IOException
- {
- //Leggo un numero in ingresso
- BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Inserisci il numero delle vendite per l'agente corrente");
- String line = input.readLine();
- //Verifico se non è negativo o se ha valore 0
- int NumeroVendite = Integer.parseInt(line);
- if (NumeroVendite<=0)
- {
- System.out.println("Inserisci un numero maggiore di 0");
- line = input.readLine();
- NumeroVendite = Integer.parseInt(line);
- }
- return NumeroVendite;
- }
- public static int ChiediImportoDiUnaVendita()throws IOException
- {
- //Leggo un numero in ingresso
- BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("Inserisci l'importo");
- String line = input.readLine();
- //Verifico se non è negativo o se ha valore 0
- int Importo = Integer.parseInt(line);
- if (Importo<=0)
- {
- System.out.println("Inserisci un numero maggiore di 0");
- line = input.readLine();
- Importo = Integer.parseInt(line);
- }
- return Importo;
- }
- public static void MediaMassimaMinimaImportoMassimoMinimo(int NumeroAgenti)throws IOException
- {
- double Massimo = 0;
- double Minimo = 99999;
- int SommaImportiAgente = 0;
- double SommaImportiAgenti = 0;
- double SommaMedieAgenti = 0;
- double MediaAgente = 0;
- double MediaTotale = 0;
- double MediaMinima = 9999;
- double MediaMassima = 0;
- for(int i = 0;i<NumeroAgenti;i++)
- {
- SommaImportiAgente = 0;
- int NumeroVendite = LeggiNumeroDiVenditePerAgenteCorrente();
- for(int z = 0; z<NumeroVendite;z++)
- {
- //Leggo il voto richiamando la funzione e poi controllo se è un voto alto o basso
- double Importo = ChiediImportoDiUnaVendita();
- SommaImportiAgente += Importo;
- if(Importo>Massimo)
- Massimo=Importo;
- if (Importo<Minimo)
- Minimo=Importo;
- }
- MediaAgente = SommaImportiAgente/NumeroVendite;
- SommaMedieAgenti += MediaAgente;
- System.out.println("La media di questo agente e' " + MediaAgente);
- //Una volta calcolata la media di un singolo agente verifico se è una media alta o bassa
- if(MediaAgente>MediaMassima)
- {
- MediaMassima=MediaAgente;
- }
- if (MediaAgente<MediaMinima)
- {
- MediaMinima = MediaAgente;
- }
- }
- MediaTotale = SommaMedieAgenti/NumeroAgenti;
- Stampa(MediaTotale, Minimo, Massimo, MediaMinima, MediaMassima);
- }
- public static void Stampa(double MediaTotale,double Minimo,double Massimo,double MediaMinima,double MediaMassima)throws IOException
- {
- //Mi occupo di stampare i risultati ottenuti dalle altre funzioni
- System.out.println("La media totale e': " + MediaTotale);
- System.out.println("La media minima e' : "+ MediaMinima);
- System.out.println("La media massima e': "+ MediaMassima);
- System.out.println("Il voto piu' basso e': "+ Minimo);
- System.out.println("Il voto piu' alto e': "+ Massimo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement