I have this code to read each line of a file of this type "603,The Matrix,1999-03-30,63000000,136,7.9,9079" but I only need to read the first 3 parameters and the 3rd one each is a date needs to be read separately, therefor it needs to put the year in a var and the month in other var and then the day in another var but the output I get is this: "[603 | The Matrix | 03-603,The Matrix,1999-1999-03-30"
int i; Scanner leitorFicheiroFilmes = new Scanner(ficheiroFilmes); ArrayList<Filmes> filme = new ArrayList<>(); for (i = 0; leitorFicheiroFilmes.hasNextLine(); i++) { String line = leitorFicheiroFilmes.nextLine(); String dados[] = linha.split(","); if (dados.length == 7) { int idFilme = Integer.parseInt(dados[0]); String titulo = dados[1]; String dadosNew[] = line.split("-"); String ano = dados[2]; String mes = dadosNew[0]; String dia = dadosNew[1]; filme.add(new Filmes(idFilme, title, year, month, day, parseActoresFile(), parseGenerosFile(idFilme))); } } this is the class with the constructor:
public class Filmes { int idFilme; String titulo; ArrayList<Actores> actores = new ArrayList<Actores>(); ArrayList<GenerosCinematograficos> generos = new ArrayList<GenerosCinematograficos>(); String year, month, day; public Filmes(int idFilme, String titulo, String year, String month, String day, ArrayList<Actores> actores, ArrayList<GenerosCinematograficos> generos) { this.idFilme = idFilme; this.titulo = titulo; this.year = year; this.month = month; this.day = day; this.actores = actores; this.generos = generos; } public String toString() { return idFilme + " | " + titulo + " | " + dia + "-" + mes + "-" + ano; } }
pandaspackage or R to deal with this sort of data. Java isn't entirely the best tool for this. However that is, stepping this through a debugger would almost certainly solve your problem trivially.