import java.io.*;
import java.util.*;
import javax.swing.JFileChooser;
/**
*
* @author Kevaughn
*/
public class AcadAdminSystem_Phase2
{
// The following lists will be populated as we read data from the input file.
// After we are done populating them, we use them to set the instance
// variables of the School object.
private static ArrayList<Instructor> schoolInstructors = new ArrayList<>();
private static ArrayList<Course> schoolCourses = new ArrayList<>();
private static ArrayList<Student> schoolStudents = new ArrayList<>();
public static void main(String[] args)
{
// create a School object
School mySchool = new School("Technical Institute of Miami", "Miami, FL");
// Prompt the user to select an input data file
File selectedFile;
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
selectedFile = fileChooser.getSelectedFile();
Scanner inputFile = null;
try
{
// Open the file for reading
inputFile = new Scanner(selectedFile);
// read all lines of data from the file and process them
String line;
int lineNumber = 1;
while (inputFile.hasNext())
{
line = inputFile.nextLine();
try
{
processLineOfData(line);
}
catch(Exception ex)
{
String message = "The following error occurred while processing line number "
+ lineNumber + ": " + ex.getMessage()
+ "\nLine of data skipped: " + line;
System.out.println( message );
}
lineNumber++;
}
}
catch (FileNotFoundException e)
{
System.out.println(e.toString());
}
finally
{
if( inputFile != null )
inputFile.close();
// After processing the entire input file, the lists should be populated
mySchool.setListOfInstructors(schoolInstructors);
mySchool.setListOfStudents(schoolStudents);
System.out.println(mySchool);
}
}
}
public static ArrayList<Instructor> getSchoolInstructors()
{
return schoolInstructors;
}
public static ArrayList<Course> getSchoolCourses()
{
return schoolCourses;
}
public static ArrayList<Student> getSchoolStudents()
{
return schoolStudents;
}
public static void setSchoolInstructors(ArrayList<Instructor> list)
{
schoolInstructors = list;
}
public static void setSchoolCourses(ArrayList<Course> list)
{
schoolCourses = list;
}
public static void setSchoolStudents(ArrayList<Student> list)
{
schoolStudents = list;
}
public static void processLineOfData(String line) throws Exception
{
//String [] characters = line.split(",");
//if(characters.equals("I"))
// provide implementation
}
public static ArrayList<CourseGrade> parseStudentCourseGrades(String courseList)
{
// provide implementation
ArrayList <CourseGrade> courseList1 = new ArrayList <CourseGrade>();
String [] courses = courseList.split("#");
String [] courseElements;
for (String test : courses)
{
courseElements = test.split(":");
test = courseElements[0];
}
//Course myCourse = new Course()
return courseList1;
}
}
Modification
1: Write a method called parseStudentCourseGrades
that has a String parameter and returns an ArrayList of CourseGrade objects.
The
parameter represents the list of courses a student has taken and you may assume
that it has the following format:
courseNumber:term:grade#courseNumber:term:grade#courseNumber:term:grade…
This
method will check if the courses passed in the parameter string are equal to
any element in the schoolCourses list,
and if it finds one, it uses it to create a CourseGrade object and adds it to
the arraylist that this method returns.
I’m
providing you with an algorithm below:
public
static ArrayList<CourseGrade> parseStudentCourseGrades(String courseList)
{
// 1- declare an ArrayList of CourseGrade elements and
initialize to an
// empty list
// 2- split the courseList parameter on the # to get each course
information
// 3- iterate through the list of courses, which should have the
following
// format: courseNumber:term:grade
// 4- Use the course number and term fields to create a Course
object.
// (this object is used
to search the schoolCourses array list)
// 5- Use the findCourse method you added to the AcadAdminUtility
class
// to see if there is a
Course element in the schoolCourses array list
// with the same course
number and term.
// 6- if the findCourse method returns a Course object (instead
of null),
// use it to create a
CourseGrade object and add it to the array list of
// CourseGrade objects
this method returns.
// 7- Return the list of CourseGrade objects.
}