Advertisement
LightProgrammer000

Lucros [acoes]

Feb 20th, 2020
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package Tarefas_1;
  2.  
  3. // Bibliotecas
  4. import java.util.Scanner;
  5.  
  6. public class EX_02
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         System.out.println("# Programa EX_02");
  11.  
  12.         try
  13.         {
  14.             // Variaveis
  15.             String letra;
  16.             double prec_comp;
  17.             double prec_vend;
  18.  
  19.             // Controle
  20.             int qtd_inf = 0;
  21.             int qtd_sup = 0;
  22.  
  23.             // Instanciacao
  24.             Scanner ent = new Scanner(System.in);
  25.  
  26.             // Estrutura de repeticao
  27.             while (true)
  28.             {
  29.                 System.out.print("\n- Tipo de acao (quaisquer letras, exceto 'f' ou 'F'): ");
  30.                 letra = ent.next();
  31.  
  32.                 // Estrutura de decisao
  33.                 if ("f".equals(letra) || "F".equals(letra))
  34.                 {
  35.                     break;
  36.                 }
  37.  
  38.                 else
  39.                 {
  40.                     System.out.print("- Preco de compra: ");
  41.                     prec_comp = ent.nextDouble();
  42.  
  43.                     System.out.print("- Preco de venda: ");
  44.                     prec_vend = ent.nextDouble();
  45.  
  46.                     if (analise_lucro(prec_comp, prec_vend) < 200)
  47.                     {
  48.                         qtd_inf = qtd_acoes_lucro_inf(qtd_inf);
  49.                     }
  50.  
  51.                     else if (analise_lucro(prec_comp, prec_vend) > 1000)
  52.                     {
  53.                         qtd_sup = qtd_acoes_lucro_sup(qtd_sup);
  54.                     }
  55.                 }
  56.             }
  57.  
  58.             // Metodo: Impressao de relatorio
  59.             imp(qtd_inf, qtd_sup);
  60.         }
  61.  
  62.         catch (Exception e)
  63.         {
  64.             //System.out.println(e);
  65.         }
  66.     }
  67.    
  68.     private static double analise_lucro(double prec_comp, double prec_vend)
  69.     {
  70.         return prec_vend - prec_comp;
  71.     }
  72.    
  73.     private static int qtd_acoes_lucro_inf(int qtd_inf)
  74.     {
  75.         return ++qtd_inf;
  76.     }
  77.    
  78.     private static int qtd_acoes_lucro_sup(int qtd_sup)
  79.     {
  80.         return ++qtd_sup;        
  81.     }
  82.    
  83.     private static void imp(int qtd_inf, int qtd_sup)
  84.     {
  85.         System.out.println("\n### RELATORIO ###");
  86.         System.out.println("# Acoes abaixo de R$ 200: " + qtd_inf);
  87.         System.out.println("# Acoes acima de R$ 1500: " + qtd_sup);
  88.         System.out.println("############################");
  89.     }  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement