Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Willian Luigi
- import java.util.*;
- class ProvaTio {
- public static void main(String[] args) {
- Scanner inp = new Scanner(System.in);
- int
- pac_erro = -1,
- pac_type = -1,
- pac_time = -1,
- pac_last = 0;
- double
- calc_pac = 0;
- int
- noEr_pac = 0,
- qt_pac = 0,
- img_pac = 0,
- upper_pac = -1,
- lower_pac = 63325;
- while (pac_last == 0) {
- pac_erro = -1;
- pac_last = -1;
- pac_time = -1;
- pac_type = -1;
- while (pac_time < 0) {
- System.out.printf("Informe o tempo em segundos: ");
- pac_time = inp.nextInt();
- }
- while (pac_erro < 0 || pac_erro > 1) {
- System.out.printf("Informe se houve erro durante o envio do pacote(0/não, 1/sim): ");
- pac_erro = inp.nextInt();
- }
- while (pac_type < 0 || pac_type > 1) {
- System.out.printf("Informe o tipo do pacote(0/texto, 1/imagem): ");
- pac_type = inp.nextInt();
- }
- while (pac_last < 0 || pac_last > 1) {
- System.out.printf("Informe existem mais pacotes(0/sim, 1/não): ");
- pac_last = inp.nextInt();
- }
- lower_pac = lower_pac > pac_time ? pac_time : lower_pac;
- upper_pac = upper_pac < pac_time ? pac_time : upper_pac;
- img_pac += pac_type == 1 ? pac_type : 0;
- noEr_pac += pac_erro == 0 ? 1 : 0;
- calc_pac += pac_time;
- qt_pac++;
- }
- calc_pac /= qt_pac;
- System.out.printf("\n----------------------------------\n");
- System.out.printf("Tempo médio de transmissão: %2.2f\n", calc_pac);
- System.out.printf("Maior tempo de transmissão: %d\n", upper_pac);
- System.out.printf("Menor tempo de transmissão: %d\n", lower_pac);
- System.out.printf("Quantidade total de pacotes com imagem/som: %d\n", img_pac);
- System.out.printf("Percentual de pacotes enviados sem erro: %d%c\n", noEr_pac * 100 / qt_pac, '%');
- System.out.printf("\n----------------------------------\n");
- }
- }
- //Willian Luigi
Advertisement
Add Comment
Please, Sign In to add comment