Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//HELP! Error Message JAVA Program ÏStudentFinder.java:88: error: cannot find sy

ID: 3830736 • Letter: #

Question

//HELP! Error Message JAVA Program

ÏStudentFinder.java:88: error: cannot find symbol
ÏÏ§Ï Student s = new Student( tokens[0], String.parseString(tokens[1].trim()), Double.parseDouble(tokens[2].trim()), Integer.parseInt(tokens[3].trim()));
ÏÏ§Ï ^
ÏÏ§Ï symbol: method parseString(String)
ÏÏ§Ï location: class String
ϼ§ÏStudentFinder.java:89: error: cannot find symbol
ÏÏ§Ï arl.add(s);

-------------------------

Assignment:

Create a class StudentFinder that reads in a list of students from a file. The Student.java class will contain name, ID, and GPA. The user will be prompted to enter the first letter of a student's name. Then by using Java 8 Streams, filter the list of students based on the user's input and print the filtered list.

-------------------------------------------

import java.io.*;


import java.util.*;


public class Student
{
  
   private String firstname;
   private String lastname;
   private double GPA;
   private int id;

  
   public Student(String firstname, String lastname, double gPA, int id) {
   super();
   this.firstname = firstname;
   this.lastname = lastname;
   GPA = gPA;
   this.id = id;
   }

  
   public String getFirstname() {
   return firstname;
   }
   public void setFirstname(String firstname) {
   this.firstname = firstname;
   }
   public String getLastname() {
   return lastname;
   }
   public void setLastname(String lastname) {
   this.lastname = lastname;
   }
   public double getGPA() {
   return GPA;
   }
   public void setGPA(double gPA) {
   GPA = gPA;
   }
   public int getId() {
   return id;
   }
   public void setId(int id) {
   this.id = id;
   }

  
   @Override
   public String toString() {
   return "Student [firstname=" + firstname + ", lastname=" + lastname
   + ", GPA=" + GPA + ", id=" + id + "]";
   }


}


------------------------------

//Code that doesn't compile

import java.io.*;
import java.util.*;


public class StudentFinder
{

   public static void main(String[] args)
   {
BufferedReader studentsBuffer = null;

   String name;
   double gpa;
   int id;
   Student st=null;
   Scanner sc=null;
   boolean flag = false;

ArrayList<Student> arl = new ArrayList<Student>();

  

try
{
String studentsLine;

studentsBuffer = new BufferedReader(new FileReader("studentinfo"));

while ((studentsLine = studentsBuffer.readLine()) != null)
{

   StudentFinder(arl,studentsLine);


}
   studentsBuffer = new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter first letter of students name first name :");
   char firstletter = studentsBuffer.readLine().charAt(0);

   for(int i=0;i<arl.size();++i)

{
   Student s = arl.get(i);
   if (Character.toLowerCase(firstletter) == (s.getFirstname().trim().toLowerCase().charAt(0)))
   {
  
flag = true;
System.out.println("Student's Name : " + s.getFirstname() +
"Student's ID : "+ s.getId() +
"Student's GPA : " + s.getGPA());
   }
  
}
  
   if(!flag)

System.out.println("There is no student that begins with the letter " + firstletter + " please select a letter and resubmit");

}

catch (FileNotFoundException e)
{

   e.printStackTrace();
   }
finally
{
try
{
   if(studentsBuffer != null) studentsBuffer.close();
}

catch (IOException studentsException)
{
   studentsException.printStackTrace();
}
}
   }

  
public static void StudentFinder(ArrayList<Student>al ,String studentCSV)
  
   {
  
String tokens[] = studentCSV.split(",+");
  
Student s = new Student( tokens[0], String.parseString(tokens[1].trim()), Double.parseDouble(tokens[2].trim()), Integer.parseInt(tokens[3].trim()));
arl.add(s);
}
  


}

Explanation / Answer

Hi, I have fixed all compile time error.

Please check and let me know in case of any issue.

import java.io.*;

import java.util.*;

public class StudentFinder

{

   public static void main(String[] args) throws IOException

   {

       BufferedReader studentsBuffer = null;

       boolean flag = false;

       ArrayList<Student> arl = new ArrayList<Student>();

       try

       {

           String studentsLine;

           studentsBuffer = new BufferedReader(new FileReader("studentinfo"));

           while ((studentsLine = studentsBuffer.readLine()) != null)

           {

               addStudent(arl,studentsLine);

           }

           studentsBuffer = new BufferedReader(new InputStreamReader(System.in));

           System.out.println("Enter first letter of students name first name :");

           char firstletter = studentsBuffer.readLine().charAt(0);

           for(int i=0;i<arl.size();++i)

           {

               Student s = arl.get(i);

               if (Character.toLowerCase(firstletter) == (s.getFirstname().trim().toLowerCase().charAt(0)))

               {

                   flag = true;

                   System.out.println("Student's Name : " + s.getFirstname() +

                           "Student's ID : "+ s.getId() +

                           "Student's GPA : " + s.getGPA());

               }

           }

           if(!flag)

               System.out.println("There is no student that begins with the letter " + firstletter + " please select a letter and resubmit");

       }

       catch (FileNotFoundException e)

       {

           e.printStackTrace();

       }

       finally

       {

           try

           {

               if(studentsBuffer != null) studentsBuffer.close();

           }

           catch (IOException studentsException)

           {

               studentsException.printStackTrace();

           }

       }

   }

   public static void addStudent(ArrayList<Student>al ,String studentCSV)

   {

       String tokens[] = studentCSV.split(",");

       // breaking name in two part: first name and last name

      

       String name[] = tokens[0].split(" ");

      

       Student s = new Student(

               name[0].trim(),

               name[1].trim(),

               Double.parseDouble(tokens[2].trim()),

               Integer.parseInt(tokens[1].trim()));

      

       al.add(s);

   }

}