Boas
Tenho para fazer um projecto em java mas estou com dificuldades, ainda sou novo nisto.
Estou em pânico porque tenho uma semana para o acabar.
Agradeço qualquer ajuda.
Projeto:
Vou receber um ficheiro input (pedidos.txt)
exemplo:
[quote]Pão (cesta de 2) : 1
Queijo de cabra : 1
Água do Luso 1.5L : 2
Salada de atum : 1
Cocacola (lata) : 1
Café : 2
Queijo de cabra : 0
blahblahblah : 1
Preciso que o programa faça:
Output: resultados
[quote]Pratos
<...>
O codigo até agora:
package projectof;
import java.util.*;
import java.io.*;
public class Projectof {
public static void main( String[] arg ) throws IOException
{
String tipo = null;
BufferedReader file = new BufferedReader(new FileReader(new File("pedidos.txt")));
Map<String,Integer> entradasLidas = new HashMap<String,Integer>();
Map<String,Integer> pratosLidos = new HashMap<String,Integer>();
Map<String,Integer> bebidasLidas = new HashMap<String,Integer>();
Map<String,Integer> sobremesasLidas = new HashMap<String,Integer>();
Map<String,Integer> outrosLidos = new HashMap<String,Integer>();
while( ( tipo = file.readLine() ) != null )
{
String spl[] = tipo.split( ":" );
tipo = spl[0].trim();
String quant = spl[1].trim();
Integer valor = new Integer( quant );
if( entradas.containsKey( tipo ) ){
Integer soma = entradasLidas.get( tipo );
if( soma == null ){
soma = 0;
}
entradasLidas.put( tipo, soma + valor );
}
else if( pratos.containsKey( tipo ) ){
Integer soma = pratosLidos.get( tipo );
if( soma == null ){
soma = 0;
}
pratosLidos.put( tipo, soma + valor );
}
file.close();
}
}