Advertisement
Eduardo_Pires

código com erro

Oct 13th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main
  4. {
  5.     public static boolean altera_preco(float preco, float porcentagem)
  6.     {
  7.        float temp;
  8.  
  9.        if(porcentagem > -100)
  10.        {
  11.            temp = 1 + porcentagem/100;
  12.            preco = preco*temp;
  13.  
  14.            return true;
  15.        }
  16.        else
  17.        {
  18.            return false;
  19.        }
  20.     }
  21.  
  22.     public static void main(String[] args)
  23.     {
  24.         String[] nome = new String[100];
  25.         float[] preco = new float[4];
  26.         int[] qtd_estoque = new int[4];
  27.  
  28.         Scanner scanf = new Scanner(System.in);
  29.  
  30.         for(int i = 0; i < 4; i++)
  31.         {
  32.  
  33.             System.out.printf("\nInforme o nome, o preco e a qtd. em estoque do produto 1:\n");
  34.             nome[i] = scanf.nextLine();
  35.             preco[i] = scanf.nextFloat();
  36.             qtd_estoque[i] = scanf.nextInt();
  37.         }
  38.  
  39.         System.out.printf("\nAumentando o preco em 10%% do produto 1 e 3");
  40.         altera_preco(preco[0], -110);
  41.         altera_preco(preco[2], 10);
  42.  
  43.         System.out.printf("\nReduzindo o preco em 5%% do produto 2");
  44.  
  45.         if(altera_preco(preco[1], -5))
  46.         {
  47.             System.out.printf("\n\nErro: preco nao alterado. Porcentagem invalida\n");
  48.         }
  49.         else
  50.         {
  51.             System.out.printf("\n\n Preco alterado com sucesso");
  52.         }
  53.  
  54.         System.out.printf("\nAlterando o preco do prod. 3");
  55.  
  56.         System.out.printf("\nAlterando o preco do prod. 3");
  57.         if (altera_preco(preco[3],-110) == false)
  58.         {
  59.             System.out.printf("\n\nErro: preco nao alterado. Porcentagem invalida\n");
  60.         }
  61.  
  62.         System.out.printf("\nProdutos Cadastrados:\n");
  63.         for (int i = 0; i < 4; i++){
  64.             System.out.printf("\nProduto: %s\nPreco: %f\nEstoque: %d", nome[i],preco[i],qtd_estoque[i]);
  65.         }
  66.  
  67.  
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement