Example #1
0
        //method to read students from csv file
        //@param:college1 object of College class where students are added to from csv file
        public static bool readStudent(College college1)
        {
            //find file named students
            string fldr = "\\stdtList.txt";
            fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + fldr;

            //set up variables for line of text and parsed line
            string textLine = "";
            string[] row;

            bool complete = false;

            //open stream reader, read file line at a time parsing student information and add to dictionary
            try
            {
                using (System.IO.StreamReader objReader = new System.IO.StreamReader(fldr))
                {
                    while ((textLine = objReader.ReadLine()) != null)
                    {

                        row = textLine.Split(',');
                        string studentId = row[0];
                        char courseType = Convert.ToChar(row[1]);
                        int courseCode = Convert.ToInt16(row[2]);
                        if (courseCode < 100)
                        {
                            //double fee = Convert.ToDouble(row[3]);
                            AdultStudent adultStudent1 = new AdultStudent(studentId, courseType, courseCode);
                            adultStudent1.setFee(adultStudent1.CourseType);
                            college1.addStudent(adultStudent1);
                        }//end if
                        else
                        {
                            char studyMode = Convert.ToChar(row[3]);
                            HNStudent hnStudent1 = new HNStudent(studentId, courseType, courseCode, studyMode);
                            college1.addStudent(hnStudent1);
                        }//end else

                    }//end while
                    complete = true;
                }//end using
            }//end try
            catch
            {
                complete = false;
                return complete;
            }//endcatch

            return complete;
        }
Example #2
0
 static void Main(string[] args)
 {
     College college1 = new College();
     Boolean readSuccess = FileManager.readStudent(college1);
     if (readSuccess == true)
     {
         college1.mainMenu();
     }
     else
     {
         Console.WriteLine("Error Reading File");
         Console.ReadLine();
     }
 }