Advertisement
Guest User

Untitled

a guest
May 27th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.IOException;
  3. import java.text.DecimalFormat;
  4. import java.text.NumberFormat;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class Main {
  9. public static void main(String[] args) throws FileNotFoundException, IOException {
  10. int idasFeira = 0;
  11. Scanner s = new Scanner(System.in);
  12. //LE AS IDAS A FEIRA
  13. idasFeira = s.nextInt();
  14. int[] produtosFeira = new int[idasFeira];
  15. Float[] totais = new Float[idasFeira];
  16.  
  17.  
  18. for (int x= 0;x<idasFeira;x++){
  19. produtosFeira[x] = s.nextInt();
  20. String[] produtos = new String[produtosFeira[x]];
  21. Float[] precos = new Float[produtos.length];
  22. //LE OS PRODUTOS DA FEIRA
  23. for (int cont=0;cont<produtosFeira[x];cont++){
  24. produtos[cont] = s.next();
  25. precos[cont] = Float.valueOf(s.next());
  26. }
  27. int produtosComprar = s.nextInt();
  28. while (produtosComprar<1 || produtosComprar>produtos.length){
  29. produtosComprar = s.nextInt();
  30. }
  31. Float total = (float) 0;
  32. for (int cont=0;cont<produtosComprar;cont++){
  33. String nomeProduto = s.next();
  34. while (nomeProduto.length()>50){
  35. nomeProduto = s.next();
  36. }
  37. Float quant = s.nextFloat();
  38. //PEGA O PRECO DO PRODUTO
  39. for (int cont2=0;cont2<produtos.length;cont2++){
  40. if (nomeProduto.equalsIgnoreCase(produtos[cont2])){
  41. total+= precos[cont2] * quant;
  42. break;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. }
  49. // System.out.println("R$ "+total);
  50. totais[x] = total;
  51.  
  52.  
  53. }
  54.  
  55. for (int cont=0;cont<totais.length;cont++){
  56. NumberFormat formatarFloat= new DecimalFormat("0.00");
  57. String c = formatarFloat.format(totais[cont]);
  58. System.out.print( "R$ " + c.replace(",", ".") + "\n");
  59.  
  60. }
  61.  
  62.  
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement