Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException, IOException {
- int idasFeira = 0;
- Scanner s = new Scanner(System.in);
- //LE AS IDAS A FEIRA
- idasFeira = s.nextInt();
- int[] produtosFeira = new int[idasFeira];
- Float[] totais = new Float[idasFeira];
- for (int x= 0;x<idasFeira;x++){
- produtosFeira[x] = s.nextInt();
- String[] produtos = new String[produtosFeira[x]];
- Float[] precos = new Float[produtos.length];
- //LE OS PRODUTOS DA FEIRA
- for (int cont=0;cont<produtosFeira[x];cont++){
- produtos[cont] = s.next();
- precos[cont] = Float.valueOf(s.next());
- }
- int produtosComprar = s.nextInt();
- while (produtosComprar<1 || produtosComprar>produtos.length){
- produtosComprar = s.nextInt();
- }
- Float total = (float) 0;
- for (int cont=0;cont<produtosComprar;cont++){
- String nomeProduto = s.next();
- while (nomeProduto.length()>50){
- nomeProduto = s.next();
- }
- Float quant = s.nextFloat();
- //PEGA O PRECO DO PRODUTO
- for (int cont2=0;cont2<produtos.length;cont2++){
- if (nomeProduto.equalsIgnoreCase(produtos[cont2])){
- total+= precos[cont2] * quant;
- break;
- }
- }
- }
- // System.out.println("R$ "+total);
- totais[x] = total;
- }
- for (int cont=0;cont<totais.length;cont++){
- NumberFormat formatarFloat= new DecimalFormat("0.00");
- String c = formatarFloat.format(totais[cont]);
- System.out.print( "R$ " + c.replace(",", ".") + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement