whiplk

Processador de pacotes

Apr 24th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. //Willian Luigi
  2. import java.util.*;
  3.  
  4. class ProvaTio {
  5.     public static void main(String[] args) {
  6.         Scanner inp = new Scanner(System.in);
  7.    
  8.         int
  9.             pac_erro = -1,
  10.             pac_type = -1,
  11.             pac_time = -1,
  12.             pac_last = 0;
  13.            
  14.         double
  15.             calc_pac = 0;
  16.            
  17.         int
  18.             noEr_pac = 0,
  19.             qt_pac = 0,
  20.             img_pac = 0,
  21.             upper_pac = -1,
  22.             lower_pac = 63325;
  23.            
  24.         while (pac_last == 0) {
  25.             pac_erro = -1;
  26.             pac_last = -1;
  27.             pac_time = -1;
  28.             pac_type = -1;
  29.            
  30.             while (pac_time < 0) {
  31.                 System.out.printf("Informe o tempo em segundos: ");
  32.                 pac_time = inp.nextInt();
  33.             }
  34.             while (pac_erro < 0 || pac_erro > 1) {
  35.                 System.out.printf("Informe se houve erro durante o envio do pacote(0/não, 1/sim): ");
  36.                 pac_erro = inp.nextInt();
  37.             }
  38.             while (pac_type < 0 || pac_type > 1) {
  39.                 System.out.printf("Informe o tipo do pacote(0/texto, 1/imagem): ");
  40.                 pac_type = inp.nextInt();
  41.             }
  42.             while (pac_last < 0 || pac_last > 1) {
  43.                 System.out.printf("Informe existem mais pacotes(0/sim, 1/não): ");
  44.                 pac_last = inp.nextInt();
  45.             }
  46.            
  47.             lower_pac = lower_pac > pac_time ? pac_time : lower_pac;
  48.             upper_pac = upper_pac < pac_time ? pac_time : upper_pac;
  49.             img_pac += pac_type == 1 ? pac_type : 0;
  50.             noEr_pac += pac_erro == 0 ? 1 : 0;
  51.             calc_pac += pac_time;
  52.             qt_pac++;          
  53.         }      
  54.         calc_pac /= qt_pac;
  55.        
  56.         System.out.printf("\n----------------------------------\n");
  57.         System.out.printf("Tempo médio de transmissão: %2.2f\n", calc_pac);
  58.         System.out.printf("Maior tempo de transmissão: %d\n", upper_pac);
  59.         System.out.printf("Menor tempo de transmissão: %d\n", lower_pac);
  60.         System.out.printf("Quantidade total de pacotes com imagem/som: %d\n", img_pac);
  61.         System.out.printf("Percentual de pacotes enviados sem erro: %d%c\n", noEr_pac * 100 / qt_pac, '%');
  62.         System.out.printf("\n----------------------------------\n");
  63.     }
  64. }
  65. //Willian Luigi
Advertisement
Add Comment
Please, Sign In to add comment