I have this string ( LIXA ABIMERHI JUAN JOSE,DISEÑO DE INTERFACES,90,88,81,90
)
and they are asking me:
split
method of the class String
separate the fields. (they are strings contained in a file)
My code:
Scanner sc = new Scanner(System.in);
File file = new File("E:/SEMESTRE2/POO/PROGRAMAS/TareasSem2/src/U6/Calificaciones.txt");
if (!file.exists())
{
System.out.println ("No existe el archivo: "+file);
System.exit(1);
}
System.out.println ("Archivo Encontrado");
System.out.print ("Escribe El Promedio Minimo ");
int prom = sc.nextInt();
try
{
FileReader fr = new FileReader(file);
BufferedReader bfr = new BufferedReader(fr);
String linea=bfr.readLine();
String[] parts = linea.split(",");
//nombre> parts[0] materia parts[1] num1 parts [2]
//System.out.println(linea);
while (linea != null)
{
double num = 0, mat, promA = 0;
for(int i = 2;i>=2&&i<=5;i++)
{
mat=Double.parseDouble(parts[i]);
num = num + mat;
promA = num / 4;
}
System.out.println(linea+" "+promA);
linea=bfr.readLine();
}
/*while (linea != null)
{
double num = 0, mat, promA = 0;
for(int i = 2;i>=2&&i<=5;i++)
{
mat=Double.parseDouble(parts[i]);
num = num + mat;
promA = num / 4;
}
System.out.println(promA);
linea=bfr.readLine();
}*/
bfr.close();
fr.close();
}
catch (java.io.FileNotFoundException ex)
{
System.out.println ("No existe el archivo: "+file);
}
catch (java.io.IOException ex)
{
System.out.println ("Error al leer el archivo: "+file);
}//fin del catch IO
ok I found just like that now it always prints the same average and does not restart