SlideShare a Scribd company logo
1 of 11
Download to read offline
i am trying to add the first four lines of a student.txt into an arraylist of type student and the next
few lines into an arraylist of type course. i have to do this for each student in the txt. However, i
keep running into errors.
Below is the students.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
My code is not working at all here is what i have
//reading through student data
ArrayList<Student> hwData = fileRdr("hw02Data.txt") ;
System.out.println("Students data: n" + hwData) ;
//reading through student data
ArrayList<Student> hwData = fileRdr("hw02Data.txt") ;
System.out.println("Students data: n" + hwData) ;
//Function definitions
//file rdr
public static ArrayList<Student> fileRdr (String fname)
throws FileNotFoundException{
ArrayList<Student> studentAL = new ArrayList <> () ;
ArrayList <Course> cAL = new ArrayList <> () ;
Scanner readFile = new Scanner(new File(fname)) ;
while(readFile.hasNextLine()) {
String name = readFile.next() ;
int id = readFile.nextInt() ;
readFile.nextLine() ;
int birthyear = readFile.nextInt() ;
boolean isSciMajor = readFile.nextBoolean() ;
readFile.nextLine() ;
Student s1 = new Student(name,id,birthyear,isSciMajor) ;
studentAL.add(s1) ;
while(readFile.hasNextLine()) {
String line = readFile.nextLine() ;
if(line == "") {
;
} //
String [] data = line.split(",") ;
Course c2 = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]) ;
cAL.add(c2) ;
System.out.println(cAL) ;
} //while loop
}
return studentAL ;
} //function call
//Function definitions
//file rdr
public static ArrayList<Student> fileRdr (String fname)
throws FileNotFoundException{
ArrayList<Student> studentAL = new ArrayList <> () ;
ArrayList <Course> cAL = new ArrayList <> () ;
Scanner readFile = new Scanner(new File(fname)) ;
while(readFile.hasNextLine()) {
String name = readFile.next() ;
int id = readFile.nextInt() ;
readFile.nextLine() ;
int birthyear = readFile.nextInt() ;
boolean isSciMajor = readFile.nextBoolean() ;
readFile.nextLine() ;
Student s1 = new Student(name,id,birthyear,isSciMajor) ;
studentAL.add(s1) ;
while(readFile.hasNextLine()) {
String line = readFile.nextLine() ;
if(line == "") {
;
} //
String [] data = line.split(",") ;
Course c2 = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]) ;
cAL.add(c2) ;
System.out.println(cAL) ;
} //while loop
}
return studentAL ;
} //function call
End of the function here is the error
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Main.fileRdr(Main.java:49)
at Main.main(Main.java:11)
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Main.fileRdr(Main.java:49)
at Main.main(Main.java:11)
please help me to fix my code
Classes for Objects They have defined: State; behavior; & how to contruct objects of the
typeCourse - name: String - courseNum: String - creditHrs: int - mode: String - meetings: String +
Course () + Course (name: String, courseNum: String, creditHrs: int, meetings: String) + tostring ()
: String + getters/setters + equals (o: Object): boolean + hashcode () : int

More Related Content

Similar to i am trying to add the first four lines of a studenttxt int.pdf

Dictionary functions and methods.ppt .
Dictionary functions and methods.ppt     .Dictionary functions and methods.ppt     .
Dictionary functions and methods.ppt .
RanjanaMalathi
 
Submit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdfSubmit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdf
akaluza07
 
how do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdfhow do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdf
footwearpark
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
sotlsoc
 

Similar to i am trying to add the first four lines of a studenttxt int.pdf (20)

Micro project project co 3i
Micro project project co 3iMicro project project co 3i
Micro project project co 3i
 
Chap 2 Arrays and Structures.ppt
Chap 2  Arrays and Structures.pptChap 2  Arrays and Structures.ppt
Chap 2 Arrays and Structures.ppt
 
Chap 2 Arrays and Structures.pptx
Chap 2  Arrays and Structures.pptxChap 2  Arrays and Structures.pptx
Chap 2 Arrays and Structures.pptx
 
Dictionary functions and methods.ppt .
Dictionary functions and methods.ppt     .Dictionary functions and methods.ppt     .
Dictionary functions and methods.ppt .
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
Submit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdfSubmit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdf
 
how do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdfhow do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdf
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
MySQL JDBC Tutorial
MySQL JDBC TutorialMySQL JDBC Tutorial
MySQL JDBC Tutorial
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARI
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016) Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016)
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Cs341
Cs341Cs341
Cs341
 
11-ch04-3-strings.pdf
11-ch04-3-strings.pdf11-ch04-3-strings.pdf
11-ch04-3-strings.pdf
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
 

More from access2future1

The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdfThe Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
access2future1
 
Second Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdfSecond Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdf
access2future1
 
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdfProporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
access2future1
 
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdfPLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
access2future1
 
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdfPatient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
access2future1
 
Please fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdfPlease fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdf
access2future1
 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdf
access2future1
 

More from access2future1 (20)

The following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdfThe following stockholders equity accounts arranged alphabe.pdf
The following stockholders equity accounts arranged alphabe.pdf
 
You are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdfYou are considering a stock investment in one of two firms .pdf
You are considering a stock investment in one of two firms .pdf
 
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdfThe Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
The Case of Sam Sawyer Sam Sawyer was a toprated operator i.pdf
 
Second Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdfSecond Republic Bank is a lending company that operates in t.pdf
Second Republic Bank is a lending company that operates in t.pdf
 
Researchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdfResearchers found that a person in a particular country spen.pdf
Researchers found that a person in a particular country spen.pdf
 
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN  USE N.pdfQUESTION 2 internal rate of return method 14 RETURN  USE N.pdf
QUESTION 2 internal rate of return method 14 RETURN USE N.pdf
 
Question 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdfQuestion 17 Which of the following contributes directly to t.pdf
Question 17 Which of the following contributes directly to t.pdf
 
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdfProporcione ejemplos de cmo Chris y Alison participaron en .pdf
Proporcione ejemplos de cmo Chris y Alison participaron en .pdf
 
Please Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdfPlease Use SWISH and write the code answer each part carefu.pdf
Please Use SWISH and write the code answer each part carefu.pdf
 
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdfPLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
PLEASE HELP ME Eric Christopher Associate Director for Glo.pdf
 
please help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdfplease help with the fill in the blanks Fill in the followin.pdf
please help with the fill in the blanks Fill in the followin.pdf
 
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdfPatient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
Patient Documentation Analysis Due Date Sunday 1159 pm MT.pdf
 
Please fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdfPlease fix the following C++ code to compile correctly in Vi.pdf
Please fix the following C++ code to compile correctly in Vi.pdf
 
output and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdfoutput and explain There is Mylist There is MyArrayList pa.pdf
output and explain There is Mylist There is MyArrayList pa.pdf
 
Name the hormones that influence the menstrual cycle Ident.pdf
Name the hormones that influence the menstrual cycle  Ident.pdfName the hormones that influence the menstrual cycle  Ident.pdf
Name the hormones that influence the menstrual cycle Ident.pdf
 
Mike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdfMike and Carol Brady realized that their house was not big e.pdf
Mike and Carol Brady realized that their house was not big e.pdf
 
Debugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdfDebugging C Console Program Debug the program to identify .pdf
Debugging C Console Program Debug the program to identify .pdf
 
742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf742 Example 743 Continued Suppose that we have iid Ber.pdf
742 Example 743 Continued Suppose that we have iid Ber.pdf
 
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdfHolt Enterprises recently paid a dividend D0 of 275 It .pdf
Holt Enterprises recently paid a dividend D0 of 275 It .pdf
 
2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf2 Use the information above to complete the Aging of Accoun.pdf
2 Use the information above to complete the Aging of Accoun.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 

i am trying to add the first four lines of a studenttxt int.pdf

  • 1. i am trying to add the first four lines of a student.txt into an arraylist of type student and the next few lines into an arraylist of type course. i have to do this for each student in the txt. However, i keep running into errors. Below is the students.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
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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 My code is not working at all here is what i have //reading through student data ArrayList<Student> hwData = fileRdr("hw02Data.txt") ; System.out.println("Students data: n" + hwData) ;
  • 8. //reading through student data ArrayList<Student> hwData = fileRdr("hw02Data.txt") ; System.out.println("Students data: n" + hwData) ; //Function definitions //file rdr public static ArrayList<Student> fileRdr (String fname) throws FileNotFoundException{ ArrayList<Student> studentAL = new ArrayList <> () ; ArrayList <Course> cAL = new ArrayList <> () ; Scanner readFile = new Scanner(new File(fname)) ; while(readFile.hasNextLine()) { String name = readFile.next() ; int id = readFile.nextInt() ; readFile.nextLine() ; int birthyear = readFile.nextInt() ; boolean isSciMajor = readFile.nextBoolean() ; readFile.nextLine() ; Student s1 = new Student(name,id,birthyear,isSciMajor) ; studentAL.add(s1) ; while(readFile.hasNextLine()) { String line = readFile.nextLine() ; if(line == "") { ; } // String [] data = line.split(",") ; Course c2 = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]) ; cAL.add(c2) ;
  • 9. System.out.println(cAL) ; } //while loop } return studentAL ; } //function call //Function definitions //file rdr public static ArrayList<Student> fileRdr (String fname) throws FileNotFoundException{ ArrayList<Student> studentAL = new ArrayList <> () ; ArrayList <Course> cAL = new ArrayList <> () ; Scanner readFile = new Scanner(new File(fname)) ; while(readFile.hasNextLine()) { String name = readFile.next() ; int id = readFile.nextInt() ; readFile.nextLine() ; int birthyear = readFile.nextInt() ; boolean isSciMajor = readFile.nextBoolean() ; readFile.nextLine() ;
  • 10. Student s1 = new Student(name,id,birthyear,isSciMajor) ; studentAL.add(s1) ; while(readFile.hasNextLine()) { String line = readFile.nextLine() ; if(line == "") { ; } // String [] data = line.split(",") ; Course c2 = new Course(data[0],data[1],Integer.parseInt(data[2]),data[3],data[4]) ; cAL.add(c2) ; System.out.println(cAL) ; } //while loop } return studentAL ; } //function call End of the function here is the error Exception in thread "main" java.util.InputMismatchException
  • 11. at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main.fileRdr(Main.java:49) at Main.main(Main.java:11) Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main.fileRdr(Main.java:49) at Main.main(Main.java:11) please help me to fix my code Classes for Objects They have defined: State; behavior; & how to contruct objects of the typeCourse - name: String - courseNum: String - creditHrs: int - mode: String - meetings: String + Course () + Course (name: String, courseNum: String, creditHrs: int, meetings: String) + tostring () : String + getters/setters + equals (o: Object): boolean + hashcode () : int