SlideShare a Scribd company logo
I wrote a function to read through all of the students in a students.txt file and add it to an arraylist
of that type. It works smooth but it's not adding the last student in the file to the arraylist. can u
help me fix my code so that 10 out of 10 students are added to an arraylist of type student?
Here is my code
public static ArrayList<Student> readDataFromFile(String fName)
throws FileNotFoundException{
ArrayList<Student> result = new ArrayList<>();
Scanner fileRdr = new Scanner(new File(fName));
String name = fileRdr.nextLine();
int sId = Integer.parseInt(fileRdr.nextLine());
int birthYr = Integer.parseInt(fileRdr.nextLine());
boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
ArrayList<Course> crseAL = new ArrayList<>();
String lineRead = fileRdr.nextLine();
while(fileRdr.hasNextLine()){
String [] data = lineRead.split(",");
Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]);
crseAL.add(c);
lineRead = fileRdr.nextLine();
//You've read all courses for a particular student
if(lineRead.equals("")){//line empty
Student s = new Student(name,sId,birthYr,sciMajor);
s.setSchedule(crseAL);
result.add(s);
//read student info for next student
name = fileRdr.nextLine();
sId = Integer.parseInt(fileRdr.nextLine());
birthYr = Integer.parseInt(fileRdr.nextLine());
sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
crseAL = new ArrayList<>();
lineRead = fileRdr.nextLine();
}
Here is the student.txt
Michael West
900753
2003
TruE
Art Appreciation,1090,3,sync,T
Data Structures,2735,5,online,MWF
Calculus,1070,4,in-person,MTWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Festus Park
900846
2000
False
Art Appreciation,1090,3,sync,T
Intro to CS,1724,4,in-person,MWTF
Statistics,2010,3,Online,MWF
Personal Finance,1070,3,online,TBD
Africa and the World,2090,3,sync,WF
Ahmed Nord
900963
2004
true
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Tasha Ohlder
900102
1994
true
Intro to Sociology,1010,3,async,MW
Data Structures,2735,5,online,MWF
Statistics,2020,4,online,MWRF
Personal Finance,1070,3,online,TBD
Intro to Theology,1080,3,async,WF
Earl Mint
900159
2003
false
Calculus,1070,4,online,MTWF
Intro to CS,1724,4,in-person,MWTF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
English Composition,2010,3,online,MWF
Katie Easton
900951
2000
false
Discrete Structs,2550,3,online,TR
Intro to CS,1724,4,in-person,MWTF
Intro to Karate,1040,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Kennedy Dotson
900237
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Personal Finance,1070,3,online,TBD
Nick Peoples
900856
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Olivia Priest
900123
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Macro Economics,2020,3,sync,TW
Personal Finance,1070,3,online,TBD
Rashad Black
900456
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
How Things Work,1010,3,async,WF
Here is my code
public static ArrayList<Student> readDataFromFile(String fName)
throws FileNotFoundException{
ArrayList<Student> result = new ArrayList<>();
Scanner fileRdr = new Scanner(new File(fName));
String name = fileRdr.nextLine();
int sId = Integer.parseInt(fileRdr.nextLine());
int birthYr = Integer.parseInt(fileRdr.nextLine());
boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
ArrayList<Course> crseAL = new ArrayList<>();
String lineRead = fileRdr.nextLine();
while(fileRdr.hasNextLine()){
String [] data = lineRead.split(",");
Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]);
crseAL.add(c);
lineRead = fileRdr.nextLine();
//You've read all courses for a particular student
if(lineRead.equals("")){//line empty
Student s = new Student(name,sId,birthYr,sciMajor);
s.setSchedule(crseAL);
result.add(s);
//read student info for next student
name = fileRdr.nextLine();
sId = Integer.parseInt(fileRdr.nextLine());
birthYr = Integer.parseInt(fileRdr.nextLine());
sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
crseAL = new ArrayList<>();
lineRead = fileRdr.nextLine();
}
public static ArrayList<Student> readDataFromFile(String fName)
throws FileNotFoundException{
ArrayList<Student> result = new ArrayList<>();
Scanner fileRdr = new Scanner(new File(fName));
String name = fileRdr.nextLine();
int sId = Integer.parseInt(fileRdr.nextLine());
int birthYr = Integer.parseInt(fileRdr.nextLine());
boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
ArrayList<Course> crseAL = new ArrayList<>();
String lineRead = fileRdr.nextLine();
while(fileRdr.hasNextLine()){
String [] data = lineRead.split(",");
Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]);
crseAL.add(c);
lineRead = fileRdr.nextLine();
//You've read all courses for a particular student
if(lineRead.equals("")){//line empty
Student s = new Student(name,sId,birthYr,sciMajor);
s.setSchedule(crseAL);
result.add(s);
//read student info for next student
name = fileRdr.nextLine();
sId = Integer.parseInt(fileRdr.nextLine());
birthYr = Integer.parseInt(fileRdr.nextLine());
sciMajor = Boolean.parseBoolean(fileRdr.nextLine());
crseAL = new ArrayList<>();
lineRead = fileRdr.nextLine();
}
Here is the student.txt
Michael West
900753
2003
TruE
Art Appreciation,1090,3,sync,T
Data Structures,2735,5,online,MWF
Calculus,1070,4,in-person,MTWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Festus Park
900846
2000
False
Art Appreciation,1090,3,sync,T
Intro to CS,1724,4,in-person,MWTF
Statistics,2010,3,Online,MWF
Personal Finance,1070,3,online,TBD
Africa and the World,2090,3,sync,WF
Ahmed Nord
900963
2004
true
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Tasha Ohlder
900102
1994
true
Intro to Sociology,1010,3,async,MW
Data Structures,2735,5,online,MWF
Statistics,2020,4,online,MWRF
Personal Finance,1070,3,online,TBD
Intro to Theology,1080,3,async,WF
Earl Mint
900159
2003
false
Calculus,1070,4,online,MTWF
Intro to CS,1724,4,in-person,MWTF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
English Composition,2010,3,online,MWF
Katie Easton
900951
2000
false
Discrete Structs,2550,3,online,TR
Intro to CS,1724,4,in-person,MWTF
Intro to Karate,1040,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Kennedy Dotson
900237
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Personal Finance,1070,3,online,TBD
Nick Peoples
900856
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Olivia Priest
900123
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Macro Economics,2020,3,sync,TW
Personal Finance,1070,3,online,TBD
Rashad Black
900456
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
How Things Work,1010,3,async,WF
Michael West
900753
2003
TruE
Art Appreciation,1090,3,sync,T
Data Structures,2735,5,online,MWF
Calculus,1070,4,in-person,MTWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Festus Park
900846
2000
False
Art Appreciation,1090,3,sync,T
Intro to CS,1724,4,in-person,MWTF
Statistics,2010,3,Online,MWF
Personal Finance,1070,3,online,TBD
Africa and the World,2090,3,sync,WF
Ahmed Nord
900963
2004
true
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Tasha Ohlder
900102
1994
true
Intro to Sociology,1010,3,async,MW
Data Structures,2735,5,online,MWF
Statistics,2020,4,online,MWRF
Personal Finance,1070,3,online,TBD
Intro to Theology,1080,3,async,WF
Earl Mint
900159
2003
false
Calculus,1070,4,online,MTWF
Intro to CS,1724,4,in-person,MWTF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
English Composition,2010,3,online,MWF
Katie Easton
900951
2000
false
Discrete Structs,2550,3,online,TR
Intro to CS,1724,4,in-person,MWTF
Intro to Karate,1040,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Health Ethics,2080,3,async,TR
Kennedy Dotson
900237
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Personal Finance,1070,3,online,TBD
Nick Peoples
900856
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
Olivia Priest
900123
1999
True
Intro to Philosophy,1070,3,online,TR
Data Structures,2735,5,online,MWF
Intro to Data Science,1070,4,in-person,MWF
Macro Economics,2020,3,sync,TW
Personal Finance,1070,3,online,TBD
Rashad Black
900456
2001
False
Intro to Sociology,1010,3,online,MW
Intro to CS,1724,4,in-person,MWTF
Intro to Tennis,1000,3,in-person,MWF
Personal Finance,1070,3,online,TBD
How Things Work,1010,3,async,WF
I wrote a function to read through all of the students in a .pdf

More Related Content

More from adianantsolutions

Name this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdfName this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdf
adianantsolutions
 
Name of Bacteria Observation Results E coli Yellow s.pdf
Name of Bacteria    Observation    Results  E coli Yellow s.pdfName of Bacteria    Observation    Results  E coli Yellow s.pdf
Name of Bacteria Observation Results E coli Yellow s.pdf
adianantsolutions
 
Nasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdfNasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdf
adianantsolutions
 
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdfMutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
adianantsolutions
 
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdfMuthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
adianantsolutions
 
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdfNadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
adianantsolutions
 
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
NAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdfNAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdf
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
adianantsolutions
 
Multi choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdfMulti choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdf
adianantsolutions
 
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdfn2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
adianantsolutions
 
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdfn Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
adianantsolutions
 
Myra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdfMyra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdf
adianantsolutions
 
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdfMycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
adianantsolutions
 
My library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdfMy library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdf
adianantsolutions
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdf
adianantsolutions
 
My essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdfMy essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdf
adianantsolutions
 
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdfMsrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
adianantsolutions
 
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdfMRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
adianantsolutions
 
Mr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdfMr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdf
adianantsolutions
 
Multiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdfMultiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdf
adianantsolutions
 
MT2992 Define the various tasks and responsibilities of ma.pdf
MT2992 Define the various tasks and responsibilities of ma.pdfMT2992 Define the various tasks and responsibilities of ma.pdf
MT2992 Define the various tasks and responsibilities of ma.pdf
adianantsolutions
 

More from adianantsolutions (20)

Name this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdfName this accessory gland to the digestive systemName th.pdf
Name this accessory gland to the digestive systemName th.pdf
 
Name of Bacteria Observation Results E coli Yellow s.pdf
Name of Bacteria    Observation    Results  E coli Yellow s.pdfName of Bacteria    Observation    Results  E coli Yellow s.pdf
Name of Bacteria Observation Results E coli Yellow s.pdf
 
Nasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdfNasopharyngeal aspirates samples are used to investigate the.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdf
 
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdfMutating His E7 the distal His in myoglobin to a Gly would.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
 
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdfMuthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
 
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdfNadine LeMieux has just inherited 8000 She wants to use t.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
 
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
NAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdfNAD  Participa en la hidrlisis de la sacarosa a glucosa  e.pdf
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
 
Multi choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdfMulti choice Which sequence represents the correct sequence .pdf
Multi choice Which sequence represents the correct sequence .pdf
 
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdfn2  1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
 
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdfn Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
 
Myra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdfMyra had high scores as cooperative team player evenkeele.pdf
Myra had high scores as cooperative team player evenkeele.pdf
 
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdfMycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
 
My library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdfMy library gt IT 145 Intro to Software Development home .pdf
My library gt IT 145 Intro to Software Development home .pdf
 
My code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdfMy code is below How do I write this code without usin.pdf
My code is below How do I write this code without usin.pdf
 
My essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdfMy essay topic is Water Pollution in black Mississippi Jacks.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdf
 
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdfMsrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
 
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdfMRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
 
Mr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdfMr senabe is a senior teacher in a secondary school he has.pdf
Mr senabe is a senior teacher in a secondary school he has.pdf
 
Multiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdfMultiple Choice that those genes are not useful in interpret.pdf
Multiple Choice that those genes are not useful in interpret.pdf
 
MT2992 Define the various tasks and responsibilities of ma.pdf
MT2992 Define the various tasks and responsibilities of ma.pdfMT2992 Define the various tasks and responsibilities of ma.pdf
MT2992 Define the various tasks and responsibilities of ma.pdf
 

Recently uploaded

How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 

Recently uploaded (20)

How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 

I wrote a function to read through all of the students in a .pdf

  • 1. I wrote a function to read through all of the students in a students.txt file and add it to an arraylist of that type. It works smooth but it's not adding the last student in the file to the arraylist. can u help me fix my code so that 10 out of 10 students are added to an arraylist of type student? Here is my code public static ArrayList<Student> readDataFromFile(String fName) throws FileNotFoundException{ ArrayList<Student> result = new ArrayList<>(); Scanner fileRdr = new Scanner(new File(fName)); String name = fileRdr.nextLine(); int sId = Integer.parseInt(fileRdr.nextLine()); int birthYr = Integer.parseInt(fileRdr.nextLine()); boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); ArrayList<Course> crseAL = new ArrayList<>(); String lineRead = fileRdr.nextLine(); while(fileRdr.hasNextLine()){ String [] data = lineRead.split(","); Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]); crseAL.add(c); lineRead = fileRdr.nextLine(); //You've read all courses for a particular student if(lineRead.equals("")){//line empty Student s = new Student(name,sId,birthYr,sciMajor); s.setSchedule(crseAL); result.add(s); //read student info for next student name = fileRdr.nextLine(); sId = Integer.parseInt(fileRdr.nextLine()); birthYr = Integer.parseInt(fileRdr.nextLine()); sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); crseAL = new ArrayList<>(); lineRead = fileRdr.nextLine(); } Here is the student.txt Michael West 900753 2003
  • 2. TruE Art Appreciation,1090,3,sync,T Data Structures,2735,5,online,MWF Calculus,1070,4,in-person,MTWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Festus Park 900846 2000 False Art Appreciation,1090,3,sync,T Intro to CS,1724,4,in-person,MWTF Statistics,2010,3,Online,MWF Personal Finance,1070,3,online,TBD Africa and the World,2090,3,sync,WF Ahmed Nord 900963 2004 true Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Tasha Ohlder 900102 1994 true Intro to Sociology,1010,3,async,MW Data Structures,2735,5,online,MWF Statistics,2020,4,online,MWRF Personal Finance,1070,3,online,TBD Intro to Theology,1080,3,async,WF Earl Mint 900159 2003 false Calculus,1070,4,online,MTWF Intro to CS,1724,4,in-person,MWTF
  • 3. Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR English Composition,2010,3,online,MWF Katie Easton 900951 2000 false Discrete Structs,2550,3,online,TR Intro to CS,1724,4,in-person,MWTF Intro to Karate,1040,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Kennedy Dotson 900237 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF Personal Finance,1070,3,online,TBD Nick Peoples 900856 2001 False Intro to Sociology,1010,3,online,MW Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Olivia Priest 900123 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF Macro Economics,2020,3,sync,TW Personal Finance,1070,3,online,TBD Rashad Black
  • 4. 900456 2001 False Intro to Sociology,1010,3,online,MW Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD How Things Work,1010,3,async,WF Here is my code public static ArrayList<Student> readDataFromFile(String fName) throws FileNotFoundException{ ArrayList<Student> result = new ArrayList<>(); Scanner fileRdr = new Scanner(new File(fName)); String name = fileRdr.nextLine(); int sId = Integer.parseInt(fileRdr.nextLine()); int birthYr = Integer.parseInt(fileRdr.nextLine()); boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); ArrayList<Course> crseAL = new ArrayList<>(); String lineRead = fileRdr.nextLine(); while(fileRdr.hasNextLine()){ String [] data = lineRead.split(","); Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]); crseAL.add(c); lineRead = fileRdr.nextLine(); //You've read all courses for a particular student if(lineRead.equals("")){//line empty Student s = new Student(name,sId,birthYr,sciMajor); s.setSchedule(crseAL); result.add(s); //read student info for next student name = fileRdr.nextLine(); sId = Integer.parseInt(fileRdr.nextLine()); birthYr = Integer.parseInt(fileRdr.nextLine()); sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); crseAL = new ArrayList<>(); lineRead = fileRdr.nextLine(); }
  • 5. public static ArrayList<Student> readDataFromFile(String fName) throws FileNotFoundException{ ArrayList<Student> result = new ArrayList<>(); Scanner fileRdr = new Scanner(new File(fName)); String name = fileRdr.nextLine(); int sId = Integer.parseInt(fileRdr.nextLine()); int birthYr = Integer.parseInt(fileRdr.nextLine()); boolean sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); ArrayList<Course> crseAL = new ArrayList<>(); String lineRead = fileRdr.nextLine(); while(fileRdr.hasNextLine()){ String [] data = lineRead.split(","); Course c = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]); crseAL.add(c); lineRead = fileRdr.nextLine(); //You've read all courses for a particular student if(lineRead.equals("")){//line empty Student s = new Student(name,sId,birthYr,sciMajor); s.setSchedule(crseAL); result.add(s); //read student info for next student
  • 6. name = fileRdr.nextLine(); sId = Integer.parseInt(fileRdr.nextLine()); birthYr = Integer.parseInt(fileRdr.nextLine()); sciMajor = Boolean.parseBoolean(fileRdr.nextLine()); crseAL = new ArrayList<>(); lineRead = fileRdr.nextLine(); } Here is the student.txt Michael West 900753 2003 TruE Art Appreciation,1090,3,sync,T Data Structures,2735,5,online,MWF Calculus,1070,4,in-person,MTWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Festus Park 900846 2000 False Art Appreciation,1090,3,sync,T Intro to CS,1724,4,in-person,MWTF Statistics,2010,3,Online,MWF Personal Finance,1070,3,online,TBD Africa and the World,2090,3,sync,WF Ahmed Nord 900963 2004 true
  • 7. Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Tasha Ohlder 900102 1994 true Intro to Sociology,1010,3,async,MW Data Structures,2735,5,online,MWF Statistics,2020,4,online,MWRF Personal Finance,1070,3,online,TBD Intro to Theology,1080,3,async,WF Earl Mint 900159 2003 false Calculus,1070,4,online,MTWF Intro to CS,1724,4,in-person,MWTF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR English Composition,2010,3,online,MWF Katie Easton 900951 2000 false Discrete Structs,2550,3,online,TR Intro to CS,1724,4,in-person,MWTF Intro to Karate,1040,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Kennedy Dotson 900237 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF
  • 8. Personal Finance,1070,3,online,TBD Nick Peoples 900856 2001 False Intro to Sociology,1010,3,online,MW Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Olivia Priest 900123 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF Macro Economics,2020,3,sync,TW Personal Finance,1070,3,online,TBD Rashad Black 900456 2001 False Intro to Sociology,1010,3,online,MW Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD How Things Work,1010,3,async,WF Michael West 900753 2003 TruE Art Appreciation,1090,3,sync,T Data Structures,2735,5,online,MWF
  • 9. Calculus,1070,4,in-person,MTWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Festus Park 900846 2000 False Art Appreciation,1090,3,sync,T Intro to CS,1724,4,in-person,MWTF Statistics,2010,3,Online,MWF Personal Finance,1070,3,online,TBD Africa and the World,2090,3,sync,WF Ahmed Nord 900963 2004 true Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR
  • 10. Tasha Ohlder 900102 1994 true Intro to Sociology,1010,3,async,MW Data Structures,2735,5,online,MWF Statistics,2020,4,online,MWRF Personal Finance,1070,3,online,TBD Intro to Theology,1080,3,async,WF Earl Mint 900159 2003 false Calculus,1070,4,online,MTWF Intro to CS,1724,4,in-person,MWTF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR English Composition,2010,3,online,MWF Katie Easton 900951
  • 11. 2000 false Discrete Structs,2550,3,online,TR Intro to CS,1724,4,in-person,MWTF Intro to Karate,1040,3,in-person,MWF Personal Finance,1070,3,online,TBD Health Ethics,2080,3,async,TR Kennedy Dotson 900237 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF Personal Finance,1070,3,online,TBD Nick Peoples 900856 2001 False Intro to Sociology,1010,3,online,MW
  • 12. Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD Olivia Priest 900123 1999 True Intro to Philosophy,1070,3,online,TR Data Structures,2735,5,online,MWF Intro to Data Science,1070,4,in-person,MWF Macro Economics,2020,3,sync,TW Personal Finance,1070,3,online,TBD Rashad Black 900456 2001 False Intro to Sociology,1010,3,online,MW Intro to CS,1724,4,in-person,MWTF Intro to Tennis,1000,3,in-person,MWF Personal Finance,1070,3,online,TBD How Things Work,1010,3,async,WF