How do I compile these java files?

0

I would like to know how to compile these java files, because I try from cmd and I get the error:

  

"can not find simbol".

Load Data

package tp2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class CargarDatos {

public static Grafo<String> cargarDatos(String filename, String delimiter) {

    Grafo<String> grafo = new Grafo<>();
    // Primera pasada para agregar las peliculas y los actores como vertices del grafo
    try {   
        File file = new File(filename); 
        BufferedReader br = new BufferedReader(new FileReader(file));     
        String st = null;
        while ((st = br.readLine()) != null) {                
            String[] values = st.split(delimiter); 
            for (int i = 0; i < values.length; i++) {
                if (!grafo.contieneVertice(values[i]))
                    grafo.agregarVertice(values[i]);
            }
        }
        br.close();
    }
    catch (IOException e) {         
        throw new IllegalArgumentException("Error al leer el archivo: " + filename); 
    } 

    // Segunda pasada para agregar aristas entre actores y peliculas en las que trabajaron
    try {   
        File file = new File(filename); 
        BufferedReader br = new BufferedReader(new FileReader(file));     
        String st = null;
        while ((st = br.readLine()) != null) {                
            String[] values = st.split(delimiter); 
            for (int i = 1; i < values.length; i++) {
                grafo.agregarArista(values[0], values[i]);
            }
        }
        br.close();
    }
    catch (IOException e) {         
        throw new IllegalArgumentException("Error al leer el archivo: " + filename); 
    } 

    return grafo;
}


// Ejemplo de uso:
//   java tp2.main "movies.txt"
// Ingrese un nombre:
//   Bacon, Kevin
public static void main(String[] args) {
    String filename  = args[0];
    String delimiter = "/";
    Grafo<String> grafo = cargarDatos(filename, delimiter);
    System.out.println("Cantidad de vertices: " + grafo.cantVertices());
    System.out.println("Ingrese un nombre: ");
    Scanner scanner = new Scanner(new java.io.BufferedInputStream(System.in));
    String source = scanner.nextLine();
    if (grafo.contieneVertice(source)) {
        for (String v: grafo.obtenerAdyacentes(source)) {
            System.out.println("   " + v);
        }
    }
    else {
        System.out.println("No hay un vertice para la entrada: " + source);
    }
}


}

Grafo

package tp2;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Grafo<V> {

private Map<V, Set<V>> lAdy = new HashMap<>();

public Grafo() { }

public boolean contieneVertice(V v) {
    return lAdy.containsKey(v);
}

public void agregarVertice(V v) {
    lAdy.put(v, new HashSet<V>());
}

public void agregarArista(V v, V w) {
    lAdy.get(v).add(w);
    lAdy.get(w).add(v);
}

public Set<V> obtenerAdyacentes(V v) {
    return lAdy.get(v);
}

public int cantVertices() {
    return lAdy.keySet().size();
}

}
    
asked by Shuzam 07.12.2018 в 00:53
source

1 answer

1

First of all, you must make sure you have the compiler installed; good for that, enter the command javac in the command line (execute cmd.exe ); Once you make sure everything is working correctly you will have to place yourself on the route where you have your class.

For example: C:\CargarDatos.java ; to compile it you execute the following sentence:

javac CargarDatos.java

This generates a file called CargarDatos.class , and to execute the compiled code in the Console you write:

java CargarDatos

Very important, the file extension is not placed (that is, the .class ). And that's it, that's how you compile from cmd .

You will find more information at: How to Compile and Execute Java Files from the cmd Console

    
answered by 07.12.2018 / 01:05
source