Advertisement
Guest User

REVEAL NO BUGS PLS

a guest
May 24th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 31.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. /*
  10.  * MACHINE PROBLEM: EnrollIt
  11.  * For IT111P - OOP 1 - A54
  12.  * Lajato, Arciaga, Tangunan
  13.  */
  14.  
  15. namespace IT111P_MP_EnrRollIT
  16. {
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.             Console.Title = "EnrollIt - Academic Enrollment";
  22.  
  23.             List<Student> students = new List<Student>();
  24.             List<Course> courses = new List<Course>() {
  25.                 new Course() { CourseCode = "COM210", CourseName = "Communication Arts", CourseCost = 1001, Students = new List<Student>() },        // [0]
  26.                 new Course() { CourseCode = "COM150", CourseName = "Radio and Television", CourseCost = 1008, Students = new List<Student>() },      // [1]
  27.                 new Course() { CourseCode = "MMA101", CourseName = "Intro to Multimedia", CourseCost = 1004, Students = new List<Student>() },       // [2]
  28.                 new Course() { CourseCode = "MMA160", CourseName = "Audio/Video Production", CourseCost = 1018, Students = new List<Student>() },    // [3]
  29.                 new Course() { CourseCode = "CS101", CourseName = "Introduction to CS", CourseCost = 1010, Students = new List<Student>() },         // [4]
  30.                 new Course() { CourseCode = "CS152", CourseName = "Human-Computer Interaction", CourseCost = 1024, Students = new List<Student>() }, // [5]
  31.                 new Course() { CourseCode = "IT111P", CourseName = "C# Programming", CourseCost = 1012, Students = new List<Student>() },            // [6]
  32.                 new Course() { CourseCode = "IT112P", CourseName = "Windows Forms", CourseCost = 1016, Students = new List<Student>() },             // [7]
  33.                 new Course() { CourseCode = "MATH004", CourseName = "Quick Maths", CourseCost = 1006, Students = new List<Student>() },              // [8]
  34.                 new Course() { CourseCode = "MATH022", CourseName = "Calculus", CourseCost = 1008, Students = new List<Student>() },                 // [9]
  35.                 new Course() { CourseCode = "MATH025", CourseName = "Theoretical Mathematics", CourseCost = 1014, Students = new List<Student>() },  // [10]
  36.                 new Course() { CourseCode = "MEC101", CourseName = "Mechanics", CourseCost = 1016, Students = new List<Student>() },                 // [11]
  37.                 new Course() { CourseCode = "ECE101", CourseName = "Circuits", CourseCost = 1022, Students = new List<Student>() },                  // [12]
  38.                 new Course() { CourseCode = "DRAW022", CourseName = "Drawing for Architecture", CourseCost = 1020, Students = new List<Student>() }  // [13]
  39.             };
  40.             List<Curriculum> curricula = new List<Curriculum>() {
  41.                 new Curriculum() { CourseProgram = "IT", Courses = new List<Course>(){ courses[0], courses[4], courses[5], courses[6], courses[7], courses[8], courses[9] } },
  42.                 new Curriculum() { CourseProgram = "CS", Courses = new List<Course>(){ courses[0], courses[4], courses[5], courses[6], courses[7], courses[8], courses[9] } },
  43.                 new Curriculum() { CourseProgram = "MMA", Courses = new List<Course>(){ courses[0], courses[2], courses[3], courses[4], courses[8] } },
  44.                 new Curriculum() { CourseProgram = "COMM", Courses = new List<Course>(){ courses[0], courses[1], courses[2], courses[3], courses[4], courses[8] } },
  45.                 new Curriculum() { CourseProgram = "ME", Courses = new List<Course>(){ courses[0], courses[4], courses[8], courses[9], courses[10], courses[11] } },
  46.                 new Curriculum() { CourseProgram = "CPE", Courses = new List<Course>(){ courses[0], courses[2], courses[4], courses[6], courses[8], courses[9], courses[10], courses[12] } },
  47.                 new Curriculum() { CourseProgram = "ECE", Courses = new List<Course>(){ courses[0], courses[2], courses[6], courses[8], courses[9], courses[10], courses[12] } },
  48.                 new Curriculum() { CourseProgram = "AR", Courses = new List<Course>(){ courses[0], courses[2], courses[6], courses[8], courses[9], courses[10], courses[13] } }
  49.             };
  50.  
  51.             int IDcount = 0;
  52.  
  53.             MainMenu(students, courses, curricula, ref IDcount);
  54.             Console.ReadKey();
  55.         }
  56.         static void MainMenu(List<Student> students, List<Course> courses, List<Curriculum> curricula, ref int ic)
  57.         {
  58.             int input = ' '; int sid = 0, co = 0;
  59.             do
  60.             {
  61.                 Console.Title = "EnrollIt - Academic Enrollment - Main Menu";
  62.                 Console.Clear();
  63.                 Console.WriteLine
  64.                     ("Welcome to EnrollIt.!" + "\n\n" +
  65.                      "[1] Register Student\n" +
  66.                      "[2] View Student Info\n\n" +
  67.                      "[3] View Curriculum\n" +
  68.                      "[4] Enroll in a course\n" +
  69.                      "[5] Show class list\n" +
  70.                      "[6] View Enrolled Subjects\n\n" +
  71.                      "[7] View Account Balances\n" +
  72.                      "[8] Pay account balances\n\n" +
  73.                      "[9] Remove A Student From A course\n" +
  74.                      "[10] Remove A Student\n\n" +
  75.                      "[11] Admin's Menu\n\n" +
  76.                      "[0] Quit\n");
  77.                 Console.Write("Enter choice: ");
  78.                 try
  79.                 {
  80.                     input = int.Parse(Console.ReadLine());
  81.                     switch (input)
  82.                     {
  83.                         case 1:
  84.                             // Register Student
  85.                             Console.WriteLine("Register Student");
  86.                             Console.Title = "EnrollIt - Register Student";
  87.                             EnterStudent(students, curricula, ref ic);
  88.                             break;
  89.                         case 2:
  90.                             // View Student Info
  91.                             Console.WriteLine("View Student Info");
  92.                             Console.Title = "EnrollIt - Student Info";
  93.                             ViewStudentInfo(students);
  94.                             break;
  95.                         case 3:
  96.                             // View Curriculum
  97.                             Console.WriteLine("View Curriculum");
  98.                             Console.Title = "EnrollIt - View Curriculum";
  99.                             ViewCurriculum(students, curricula, ref sid, ref co);
  100.                             break;
  101.                         case 4:
  102.                             // Enroll in a Course
  103.                             Console.WriteLine("Enroll in a Course");
  104.                             Console.Title = "EnrollIt - Enroll in a Course";
  105.                             EnrollInCourse(students, courses, curricula, ref sid, ref co);
  106.                             break;
  107.                         case 5:
  108.                             // Show class list
  109.                             Console.WriteLine("Show class list");
  110.                             Console.Title = "EnrollIt - Class List";
  111.                             ShowClassList(courses, curricula);
  112.                             break;
  113.                         case 6:
  114.                             // View Enrolled Subjects
  115.                             Console.WriteLine("View Enrolled Subjects");
  116.                             Console.Title = "EnrollIt - Enrolled Subjects";
  117.                             ViewEnrolledClasses(students);
  118.                             break;
  119.                         case 7:
  120.                             // View account balances
  121.                             Console.WriteLine("View account balances");
  122.                             Console.Title = "EnrollIt - Account Balances";
  123.                             ViewPaymentInfo(students);
  124.                             break;
  125.                         case 8:
  126.                             // Pay account balances
  127.                             Console.WriteLine("Pay account balances");
  128.                             Console.Title = "EnrollIt - Balance Payment";
  129.                             PayBalances(students);
  130.                             break;
  131.                         case 9:
  132.                             Console.WriteLine("Remove A Student from a course");
  133.                             RemoveStudentFromACourse(students, courses);
  134.                             break;
  135.                         case 99:
  136.                             Console.WriteLine("Show available courses");
  137.                             ShowCourses(courses, curricula);
  138.                             break;
  139.                         case 10:
  140.                             Console.WriteLine("Remove a student");
  141.                             RemoveStudent(students);
  142.                             break;
  143.                         case 11:
  144.                             Console.WriteLine("Admin's Menu");
  145.                             Console.Title = "EnrollIt - Admin";
  146.                             AdminsMenu(students, courses, curricula);
  147.                             break;
  148.                         case 0:
  149.                             // Quit
  150.                             Console.Write("Thank you. Have a nice day.! :) ");
  151.                             Console.ReadKey();
  152.                             Environment.Exit(0);
  153.                             break;
  154.                         default:
  155.                             Console.Write("Invalid key entered: {0} ", input);
  156.                             break;
  157.                     }
  158.                     Console.ReadKey();
  159.                 }
  160.                 catch (Exception x)
  161.                 {
  162.                     Console.WriteLine("Opps: {0}\n{1}", x.GetType(), x.Message);
  163.                     Console.ReadKey();
  164.                 }
  165.  
  166.             } while (input != '0');
  167.         }
  168.         static void AdminsMenu(List<Student> students, List<Course> courses, List<Curriculum> curricula)
  169.         {
  170.             string username = "Admin";
  171.             string password = "it111p";
  172.             string user, pass;
  173.             bool check = false;
  174.             do
  175.             {
  176.  
  177.                 Console.WriteLine("Login");
  178.                 Console.Write("Username: ");
  179.                 user = Console.ReadLine();
  180.                 Console.Write("Password: ");
  181.                 pass = Console.ReadLine();
  182.  
  183.                 if (user == username && pass == password)
  184.                 {
  185.                     Console.WriteLine("You have been logged in.");
  186.                     Console.ReadKey();
  187.                     Console.Clear();
  188.                     check = true;
  189.                 }
  190.                 else
  191.                 {
  192.                     Console.WriteLine("Incorrect Username & Password.");
  193.                     Console.ReadKey();
  194.                     Console.Clear();
  195.                 }
  196.             } while (user != username && pass != password);
  197.             if (check == true)
  198.             {
  199.                 int choice1;
  200.                 do
  201.                 {
  202.                     Console.WriteLine("[1] Add Course");
  203.                     Console.WriteLine("[2] Remove Student");
  204.                     Console.WriteLine("[3] Add Course to curriculum");
  205.                     Console.WriteLine("[4] Exit");
  206.                     Console.Write("Select a Choice: ");
  207.                     choice1 = int.Parse(Console.ReadLine());
  208.                     if (choice1 == 1)
  209.                     {
  210.                         string newCourseCode = " ";
  211.                         string newCourseName = " ";
  212.                         double courseCost = 0;
  213.                         Console.Write("Add New Course Code: ");
  214.                         newCourseCode = Console.ReadLine();
  215.                         Console.Write("Add new Course Name: ");
  216.                         newCourseName = Console.ReadLine();
  217.                         Console.Write("Add new Course Cost: ");
  218.                         courseCost = int.Parse(Console.ReadLine());
  219.                         courses.Add(new Course() { CourseCode = newCourseCode, CourseName = newCourseName, CourseCost = courseCost, Students = new List<Student>() });
  220.                         Console.WriteLine("Course Added!");
  221.                         Console.ReadKey();
  222.                         Console.Clear();
  223.                     }
  224.                     if (choice1 == 2)
  225.                     {
  226.                         Console.WriteLine("Remove Course");
  227.                         for (int j = 0; j < courses.Count; j++)
  228.                         {
  229.                             Console.WriteLine("[{0}] {1} - {2}", j, courses[j].CourseCode, courses[j].CourseName);
  230.                         }
  231.                         Console.Write("Select A Course: ");
  232.                         int selectedRemove = int.Parse(Console.ReadLine());
  233.                         courses.RemoveAt(selectedRemove);
  234.                         Console.WriteLine("Course Removed!");
  235.                         Console.ReadKey();
  236.                         Console.Clear();
  237.                     }
  238.                     if (choice1 == 3)
  239.                     {
  240.                         for (int i = 0; i < curricula.Count; i++)
  241.                         {
  242.                             Console.WriteLine("[{0}] {1} ", i, curricula[i].CourseProgram);
  243.                         }
  244.                         Console.Write("Select a program: ");
  245.                         int selectedProg = int.Parse(Console.ReadLine());
  246.                         // Console.Clear();
  247.                         for (int j = 0; j < courses.Count; j++)
  248.                         {
  249.                             Console.WriteLine("[{0}] {1} - {2}", j, courses[j].CourseCode, courses[j].CourseName);
  250.                         }
  251.                         Console.Write("Select a course to be added in {0}: ", curricula[selectedProg].CourseProgram);
  252.                         int selectedCourse = int.Parse(Console.ReadLine());
  253.                         curricula[selectedProg].Courses.Add(courses[selectedCourse]);
  254.                         Console.WriteLine("Course successfully added to the program!");
  255.                         Console.ReadKey();
  256.                         Console.Clear();
  257.                     }
  258.                 } while (choice1 != 4);
  259.             }
  260.  
  261.         }
  262.         // Mejo buggy
  263.         static void RemoveStudentFromACourse(List<Student> students, List<Course> courses)
  264.         {
  265.             int enterStudID = EnterStudentID(students);
  266.             int count = 0, count2 = 0;
  267.             int selectedCourse = 0;
  268.             for (int i = 0; i < students.Count; i++)
  269.             {
  270.                 if (students[i].StudentId == enterStudID)
  271.                 {
  272.                     break;
  273.                 }
  274.                 count++;
  275.             }
  276.             Console.WriteLine("Available Courses: ");
  277.             for (int i = 0; i < courses.Count; i++)
  278.             {
  279.                 Console.WriteLine("[{0}] {1} - {2}", i, courses[i].CourseCode, courses[i].CourseName);
  280.             }
  281.             Console.WriteLine("Enrolled Courses: ");
  282.             for (int i = 0; i < students[count].Courses.Count; i++)
  283.             {
  284.                 Console.WriteLine("[{0}] {1} - {2}", i, students[count].Courses[i].CourseCode, students[count].Courses[i].CourseName);
  285.                 count2 = i;
  286.             }
  287.             Console.Write("Select A course: ");
  288.             selectedCourse = int.Parse(Console.ReadLine());
  289.  
  290.             //for (int i = 0; i < courses[selectedCourse].Students.Count; i++)
  291.             //{
  292.             //    if (courses[selectedCourse].Students[i].StudentId == enterStudID)
  293.             //    {
  294.             //        break;
  295.             //    }
  296.             //    count2++;
  297.             //}
  298.  
  299.             students[count].Courses.RemoveAt(selectedCourse);  // <-- This works
  300.             //courses[8].Students.RemoveAt(0); // <-- Kunwari ganto
  301.             // GUYS I REALLY NEED YOUR HELP! HINDI NA AKO NAKTULOG DAHIL LANG DITO!!!!
  302.             // courses[selectedCourse].Students.RemoveAt(0);      // <-- ******* eto talga pahamak ehhh
  303.              courses[selectedCourse].Students.RemoveAt(count2); // <-- eh eto kaya
  304.             Console.WriteLine("OK ba?");
  305.  
  306.             // Console.WriteLine("Student Successfully removed!");
  307.         }
  308.         // This only removes the student from the List<Student> students, not from courses.Students
  309.         static void RemoveStudent(List<Student> students)
  310.         {
  311.             Console.WriteLine("Remove Student");
  312.             int enterStudID = EnterStudentID(students);
  313.             int count = 0;
  314.             for (int i = 0; i < students.Count; i++)
  315.             {
  316.                 if (students[i].StudentId == enterStudID)
  317.                 {
  318.                     break;
  319.                 }
  320.                 count++;
  321.             }
  322.             students.RemoveAt(count);
  323.             Console.WriteLine("Student Successfully Removed!");
  324.         }
  325.         static void EnterStudent(List<Student> s, List<Curriculum> ca, ref int c)
  326.         {
  327.             string inputName;
  328.             int yrLvl, sNum, inProg;
  329.             Console.Write("Enter name: ");
  330.             inputName = Console.ReadLine();
  331.             for (int i = 0; i < ca.Count; i++)
  332.             {
  333.                 Console.Write("[{0}] {1} ", i, ca[i].CourseProgram);
  334.             }
  335.             Console.Write("\nEnter program: ");
  336.             inProg = int.Parse(Console.ReadLine());
  337.             Console.Write("Enter year level: ");
  338.             yrLvl = int.Parse(Console.ReadLine());
  339.             sNum = ((DateTime.Now.Year) * 1000) + (++c);
  340.             s.Add(new Student() { Name = inputName, CourseProgram = ca[inProg].CourseProgram, CPNum = inProg, YearLevel = yrLvl, StudentId = sNum, Courses = new List<Course>(), Payment = new Payment() });
  341.             Console.Write("Student added.");
  342.         }
  343.         static void ViewStudentInfo(List<Student> students)
  344.         {
  345.             FileStream file = new FileStream(@"studentlist.txt", FileMode.Create, FileAccess.Write);
  346.             StreamWriter writer = new StreamWriter(file);
  347.  
  348.             Console.Clear();
  349.             Console.WriteLine("List of Students: ");
  350.             writer.WriteLine("List of Students: ");
  351.             Console.WriteLine(("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  352.             writer.WriteLine(("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  353.             foreach (var stud in students)
  354.             {
  355.                 Console.WriteLine("{0}\t{1}\t{2}\t{3}", stud.Name.PadRight(36), Convert.ToString(stud.StudentId).PadRight(10),
  356.                     Convert.ToString(stud.YearLevel).PadRight(10), stud.CourseProgram.PadRight(8));
  357.                 writer.WriteLine("{0}\t{1}\t{2}\t{3}", stud.Name.PadRight(36), Convert.ToString(stud.StudentId).PadRight(10),
  358.                     Convert.ToString(stud.YearLevel).PadRight(10), stud.CourseProgram.PadRight(8));
  359.             }
  360.  
  361.             writer.Close();
  362.             file.Close();
  363.         }
  364.         static void ShowCourses(List<Course> courses, List<Curriculum> curricula)
  365.         {
  366.             Console.WriteLine("Available Courses: ");
  367.             for (int i = 0; i < courses.Count; i++)
  368.                 Console.WriteLine("[{0}] {1} - {2}", i, courses[i].CourseCode, courses[i].CourseName);
  369.         }
  370.         static void ViewCurriculum(List<Student> students, List<Curriculum> curricula, ref int sn, ref int co)
  371.         {
  372.             sn = EnterStudentID(students);
  373.             if (sn == 0)
  374.                 return;
  375.  
  376.             co = 0;
  377.             for (int i = 0; i < students.Count; i++)
  378.             {
  379.                 if (students[i].StudentId == sn)
  380.                 {
  381.                     break;
  382.                 }
  383.                 co++;
  384.             }
  385.  
  386.             Console.WriteLine("Available Courses: ");
  387.             for (int i = 0; i < curricula[students[co].CPNum].Courses.Count; i++)
  388.                 Console.WriteLine("[{0}] {1} - {2}", i, curricula[students[co].CPNum].Courses[i].CourseCode, curricula[students[co].CPNum].Courses[i].CourseName);
  389.         }
  390.         static void EnrollInCourse(List<Student> students, List<Course> courses, List<Curriculum> curricula, ref int sn, ref int co)
  391.         {
  392.             ViewCurriculum(students, curricula, ref sn, ref co);
  393.             if (sn == 0)
  394.                 return;
  395.  
  396.             Console.Write("Enter course: ");
  397.             int selectedCourse = int.Parse(Console.ReadLine());
  398.             bool check1 = true;
  399.             co = 0;
  400.             for (int i = 0; i < curricula[students[co].CPNum].Courses[selectedCourse].Students.Count; i++)
  401.             {
  402.                 if (sn == curricula[students[co].CPNum].Courses[selectedCourse].Students[i].StudentId)
  403.                 {
  404.                     Console.WriteLine("Student is already enrolled in this course!");
  405.                     check1 = false;
  406.                     return;
  407.                 }
  408.             }
  409.             if (check1 == true)
  410.             {
  411.                 for (int i = 0; i < students.Count; i++)
  412.                 {
  413.                     if (students[i].StudentId == sn)
  414.                     {
  415.                         break;
  416.                     }
  417.                     co++;
  418.                 }
  419.                 students[co].Payment.TotalPayable += courses[selectedCourse].CourseCost;
  420.                 students[co].Payment.Balance += courses[selectedCourse].CourseCost;
  421.                 curricula[students[co].CPNum].Courses[selectedCourse].Students.Add(students[co]); // <-- Fix this
  422.                 students[co].Courses.Add(curricula[students[co].CPNum].Courses[selectedCourse]);  // <-- Keep this
  423.                 Console.WriteLine("Course added.!");
  424.             }
  425.         }
  426.         static void ShowClassList(List<Course> courses, List<Curriculum> curricula)
  427.         {
  428.             FileStream file = new FileStream(@"classlist.txt", FileMode.Create, FileAccess.Write);
  429.             StreamWriter writer = new StreamWriter(file);
  430.  
  431.             Console.Clear();
  432.             ShowCourses(courses, curricula);
  433.             Console.Write("Enter course: ");
  434.             int selectedCourse = int.Parse(Console.ReadLine());
  435.             Console.WriteLine("Class List");
  436.             writer.WriteLine("Class List");
  437.             Console.WriteLine("{0}: {1}", courses[selectedCourse].CourseCode, courses[selectedCourse].CourseName);
  438.             writer.WriteLine("{0}: {1}", courses[selectedCourse].CourseCode, courses[selectedCourse].CourseName);
  439.             Console.WriteLine(("No.").PadLeft(4) + "\t" + ("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  440.             writer.WriteLine(("No.").PadLeft(4) + "\t" + ("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  441.             int count = 1;
  442.             foreach (var st in courses[selectedCourse].Students)
  443.             {
  444.                 Console.WriteLine("[{4}]\t{0}\t{1}\t{2}\t{3}", st.Name.PadRight(36), Convert.ToString(st.StudentId).PadRight(10),
  445.                     Convert.ToString(st.YearLevel).PadRight(10), st.CourseProgram.PadRight(8), Convert.ToString(count).PadLeft(2, '0'));
  446.                 writer.WriteLine("[{4}]\t{0}\t{1}\t{2}\t{3}", st.Name.PadRight(36), Convert.ToString(st.StudentId).PadRight(10),
  447.                     Convert.ToString(st.YearLevel).PadRight(10), st.CourseProgram.PadRight(8), Convert.ToString(count).PadLeft(2, '0'));
  448.                 count++;
  449.             }
  450.             writer.Close();
  451.             file.Close();
  452.         }
  453.         static void ViewEnrolledClasses(List<Student> students)
  454.         {
  455.             int enterStudID = EnterStudentID(students);
  456.             if (enterStudID == 0)
  457.                 return;
  458.  
  459.             int count = 0;
  460.             for (int i = 0; i < students.Count; i++)
  461.             {
  462.                 if (students[i].StudentId == enterStudID)
  463.                 {
  464.                     break;
  465.                 }
  466.                 count++;
  467.             }
  468.  
  469.             Console.WriteLine("Enrolled in: ");
  470.             foreach (var s in students[count].Courses)
  471.                 Console.WriteLine("{0} - {1}", s.CourseCode, s.CourseName);
  472.  
  473.         }
  474.         static void ViewPaymentInfo(List<Student> students)
  475.         {
  476.             FileStream file = new FileStream(@"ecm.txt", FileMode.Create, FileAccess.Write);
  477.             StreamWriter writer = new StreamWriter(file);
  478.  
  479.             int enterStudID = EnterStudentID(students);
  480.             if (enterStudID == 0)
  481.                 return;
  482.  
  483.             int count = 0;
  484.             for (int i = 0; i < students.Count; i++)
  485.             {
  486.                 if (students[i].StudentId == enterStudID)
  487.                 {
  488.                     break;
  489.                 }
  490.                 count++;
  491.             }
  492.  
  493.             writer.WriteLine("Certificate of Matriculation");
  494.             writer.WriteLine("Name: {0} \t ID: {1} \t Program: {2} \t Year: {3}",
  495.                 students[count].Name, students[count].StudentId, students[count].CourseProgram, students[count].YearLevel);
  496.  
  497.             Console.WriteLine("Enrolled in: ");
  498.             foreach (var s in students[count].Courses)
  499.             {
  500.                 Console.WriteLine("{0} - {1} - {2}", s.CourseCode, s.CourseName, s.CourseCost);
  501.                 writer.WriteLine("{0} - {1} - {2}", s.CourseCode, s.CourseName, s.CourseCost);
  502.             }
  503.             Console.WriteLine("Total amount payable: {0}", students[count].Payment.TotalPayable);
  504.             writer.WriteLine("Total amount payable: {0}", students[count].Payment.TotalPayable);
  505.             Console.WriteLine("Total Amount Balance left: {0}", students[count].Payment.Balance);
  506.  
  507.             writer.Close();
  508.             file.Close();
  509.         }
  510.         static void PayBalances(List<Student> students)
  511.         {
  512.             FileStream file = new FileStream(@"receipt.txt", FileMode.Create, FileAccess.Write);
  513.             StreamWriter writer = new StreamWriter(file);
  514.  
  515.             double amount = 0, change = 0, topay = 0;
  516.             int enterStudID = EnterStudentID(students);
  517.             if (enterStudID == 0)
  518.                 return;
  519.             int count = 0;
  520.  
  521.             writer.WriteLine("Official Receipt");
  522.  
  523.             for (int i = 0; i < students.Count; i++)
  524.             {
  525.                 if (students[i].StudentId == enterStudID)
  526.                 {
  527.                     break;
  528.                 }
  529.                 count++;
  530.             }
  531.             if (students[count].Payment.Balance <= 0)
  532.             {
  533.                 Console.WriteLine("No balance left!");
  534.                 return;
  535.             }
  536.             else
  537.             {
  538.                 topay = students[count].Payment.Balance;
  539.                 Console.WriteLine("To pay: {0}", topay);
  540.                 Console.Write("Enter Payment: ");
  541.                 amount = int.Parse(Console.ReadLine());
  542.                 writer.WriteLine("Name: {0} \t ID: {1} \t Program: {2} \t Year: {3}",
  543.                     students[count].Name, students[count].StudentId, students[count].CourseProgram, students[count].YearLevel);
  544.                 change = amount - students[count].Payment.Balance;
  545.                 students[count].Payment.Balance -= amount;
  546.                 Console.WriteLine("Amount Paid: " + amount);
  547.                 Console.WriteLine("Change: " + change);
  548.                 writer.WriteLine("Amount Due: " + topay);
  549.                 writer.WriteLine("Amount Paid: " + amount);
  550.                 writer.WriteLine("Change: " + change);
  551.                 if (students[count].Payment.Balance <= 0)
  552.                 {
  553.                     students[count].Payment.Balance = 0;
  554.                     Console.WriteLine("Balance Left: {0}", students[count].Payment.Balance);
  555.                 }
  556.                 else
  557.                 {
  558.                     Console.WriteLine("Balance Left: " + students[count].Payment.Balance);
  559.                 }
  560.             }
  561.  
  562.             writer.Close();
  563.             file.Close();
  564.         }
  565.         static int EnterStudentID(List<Student> students)
  566.         {
  567.             int enterStudID;
  568.             string name = " ";
  569.             int YearLevel = ' ';
  570.             string CourseProgram = " ";
  571.             int studID = ' ';
  572.             char choice = ' ';
  573.             bool check = false;
  574.  
  575.             do
  576.             {
  577.                 Console.Write("Enter Student ID: ");
  578.                 enterStudID = int.Parse(Console.ReadLine());
  579.                 for (int i = 0; i < students.Count; i++)
  580.                 {
  581.                     if (students[i].StudentId == enterStudID)
  582.                     {
  583.                         check = true;
  584.                     }
  585.                 }
  586.                 if (check == false)
  587.                 {
  588.                     Console.WriteLine("Student not found!");
  589.                     Console.Write("Do you want to try again [Y/N]? ");
  590.                     choice = char.Parse(Console.ReadLine());
  591.                 }
  592.                 if (check == true)
  593.                 {
  594.                     break;
  595.                 }
  596.             } while (choice != 'n');
  597.             if (choice == 'n')
  598.                 return 0;
  599.             if (check == true)
  600.             {
  601.                 for (int i = 0; i < students.Count; i++)
  602.                 {
  603.                     if (students[i].StudentId == enterStudID)
  604.                     {
  605.                         studID = enterStudID;
  606.                         name = students[i].Name;
  607.                         YearLevel = students[i].YearLevel;
  608.                         CourseProgram = students[i].CourseProgram;
  609.                         break;
  610.                     }
  611.                 }
  612.                 Console.Clear();
  613.                 Console.WriteLine("Student ID: " + studID);
  614.                 Console.WriteLine("Name: " + name);
  615.                 Console.WriteLine("Year level: " + YearLevel);
  616.                 Console.WriteLine("Course Program: " + CourseProgram);
  617.             }
  618.             return enterStudID;
  619.         }
  620.     }
  621.     public class Student
  622.     {
  623.         public int StudentId { get; set; }
  624.         public string Name { get; set; }
  625.         public int YearLevel { get; set; }
  626.         public string CourseProgram { get; set; }
  627.         public int CPNum { get; set; }
  628.         public List<Course> Courses { get; set; }
  629.         public Payment Payment { get; set; }
  630.     }
  631.     public class Course
  632.     {
  633.         public string CourseCode { get; set; }
  634.         public string CourseName { get; set; }
  635.         public double CourseCost { get; set; }
  636.         public List<Student> Students { get; set; }
  637.     }
  638.     public class Curriculum
  639.     {
  640.         public string CourseProgram { get; set; }
  641.         public List<Course> Courses { get; set; }
  642.     }
  643.     public class Payment : Student
  644.     {
  645.         private double TotalAmountPayable { get; set; }
  646.         private double BalanceLeft { get; set; }
  647.  
  648.         public double TotalPayable
  649.         {
  650.             get
  651.             {
  652.                 return TotalAmountPayable;
  653.             }
  654.             set
  655.             {
  656.                 TotalAmountPayable = value;
  657.             }
  658.         }
  659.         public double Balance
  660.         {
  661.             get
  662.             {
  663.                 return BalanceLeft;
  664.             }
  665.             set
  666.             {
  667.                 BalanceLeft = value;
  668.             }
  669.  
  670.         }
  671.     }
  672. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement