So I'm a C++ programmer and i'm learning Java, I've had several issues while reading int and strings, since after the int in Java it doesn't ignore the \n, like it would be in c++ with the cin.ignore, but, that's why I decided to use the Integer.parseInt...
Although, that's not my real problem, my real problem comes later, in the second while loop, that it never ends, even though it reads the end character *, it just won't end.
This is the file content:
CircumsTest
25
150754
UnitedPhase
UP
18852
John C
12345678A
Marcal B
23456789B
*
ComunismT
CT
6969
Laura D
22233300T
Alex M
22355567I
*
*
And the code, nomCandidat is just a string Name which will indicate me the name of the Candidate and in case there are no more to read, it will be an * to end.
public static void llegirCircumscripcio(Circumscripcio c) throws FileNotFoundException
{
File file = new File("ProcesElectoral.txt");
Scanner sc = new Scanner(file);
String nomCircumscripcio = sc.nextLine();
int nEscons = Integer.parseInt(sc.nextLine());
int votsValids = Integer.parseInt(sc.nextLine());
String nomPartit, siglesPartit; int votsPartit;
String nomCandidat, dniCandidat;
c = new Circumscripcio(nomCircumscripcio,nEscons,votsValids);
nomPartit = sc.nextLine();
while(nomPartit != "*"){
siglesPartit = sc.nextLine();
votsPartit = Integer.parseInt(sc.nextLine());
Partit p = new Partit(siglesPartit,nomPartit,votsPartit);
nomCandidat = sc.nextLine();
while(nomCandidat != "*"){
System.out.println(nomCandidat);
dniCandidat = sc.nextLine();
p.afegirCandidat(new Candidat(nomCandidat,dniCandidat));
nomCandidat = sc.nextLine();
}
System.out.println("arribo");
p.mostrarPartit();
c.afegirPartit(p);
nomPartit = sc.nextLine();
}
sc.close();
}
public static void main(String[] args) throws FileNotFoundException {
Circumscripcio c = new Circumscripcio();
llegirCircumscripcio(c);
c.mostrarCircumscripcio();
// TODO code application logic here
}
Thanks for your help.