I have made an ArrayList.txt which contains a list of students with their grades, a separate class student containing getName(), getGrade(), getMarks() etc and on my main class, I have a main method which will pull from this method
Hence my method goes as this:
public static String findName(ArrayList<Student> o, String name) {
for(int i = 0; i < o.size(); i++)
{
if(o.get(i).getName().startsWith(name.toLowerCase()))
System.out.print(o.get(i));
}
return name;
}
and my main method has this
findName(students, "al");
my array.txt looks something like this
afafwafa
B
80
alicegg
C
70
lfhif
D
50
Allllleeee
A
94
however my findName() method is unable to pull all names that starts with "al" even though all my other methods are working. Also I need to take note that the method should be case insensitive and i need to use .startsWith(). Any suggestions?
To add on, with the given ArrayList of type student with a string file name, i need to create a method that will write the members of the arraylist to a text file with a given name with 1 element to a line using student class toString method format. i need to handle possible exceptions with try/catch. I also need to use either filereader, fileoutputsteam, printwriter, printstream in the code
public static void nameToFile(ArrayList<Student> a, String file) {
int i = inone.read();
FileReader inone = new FileReader(a.get(i).toString());
FileOutputStream fos = new FileOutputStream(file);
PrintWriter outone = new PrintWriter(fos);
outone.close();
}
my main method has this
nameToFile(students2,"modified.txt");
toLowerCase()aftergetName()too?