Advertisement
Guest User

ADDED FEATURES

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