Advertisement
Guest User

Untitled

a guest
May 24th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 30.08 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 A Course");
  204.                     Console.WriteLine("[3] Add Course to curriculum");
  205.                     Console.WriteLine("[3] 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.                     }
  235.                     if (choice1 == 2)
  236.                     {
  237.                         for (int i = 0; i < curricula.Count; i++)
  238.                         {
  239.                             Console.WriteLine("[{0}] {1} ", i, curricula[i].CourseProgram);
  240.                         }
  241.                         Console.Write("Select a program: ");
  242.                         int selectedProg = int.Parse(Console.ReadLine());
  243.                         // Console.Clear();
  244.                         for (int j = 0; j < courses.Count; j++)
  245.                         {
  246.                             Console.WriteLine("[{0}] {1} - {2}", j, courses[j].CourseCode, courses[j].CourseName);
  247.                         }
  248.                         Console.Write("Select a course to be added in {0}: ", curricula[selectedProg].CourseProgram);
  249.                         int selectedCourse = int.Parse(Console.ReadLine());
  250.                         curricula[selectedProg].Courses.Add(courses[selectedCourse]);
  251.                         Console.WriteLine("Course successfully added to the program!");
  252.                         Console.ReadKey();
  253.                         Console.Clear();
  254.                     }
  255.                 } while (choice1 != 3);
  256.             }
  257.  
  258.         }
  259.         // Mejo buggy
  260.         //Hindi siya buggy>>
  261.         static void RemoveStudentFromACourse(List<Student> students, List<Course> courses)
  262.         {
  263.             int enterStudID = EnterStudentID(students);
  264.             int count = 0;
  265.             for (int i = 0; i < students.Count; i++)
  266.             {
  267.                 if (students[i].StudentId == enterStudID)
  268.                 {
  269.                     break;
  270.                 }
  271.                 count++;
  272.             }
  273.            
  274.             Console.WriteLine("Enrolled Courses: ");
  275.             for (int i = 0; i < students[count].Courses.Count; i++)
  276.             {
  277.                 Console.WriteLine("[{0}] {1} - {2}", i, students[count].Courses[i].CourseCode, students[count].Courses[i].CourseName);
  278.                
  279.             }
  280.             int selectedCourse = 0;
  281.             Console.Write("Select A course: ");
  282.             selectedCourse = int.Parse(Console.ReadLine());
  283.             students[count].Courses.RemoveAt(count);
  284.             courses[selectedCourse].Students.RemoveAt(count);
  285.             Console.WriteLine("Student Successfully removed!");
  286.  
  287.  
  288.         }
  289.         // This only removes the student from the List<Student> students, not from courses.Students
  290.         static void RemoveStudent(List<Student> students)
  291.         {
  292.             Console.WriteLine("Remove Student");
  293.             int enterStudID = EnterStudentID(students);
  294.             int count = 0;
  295.             for (int i = 0; i < students.Count; i++)
  296.             {
  297.                 if (students[i].StudentId == enterStudID)
  298.                 {
  299.                     break;
  300.                 }
  301.                 count++;
  302.             }
  303.             students.RemoveAt(count);
  304.             Console.WriteLine("Student Successfully Removed!");
  305.         }
  306.         static void EnterStudent(List<Student> s, List<Curriculum> ca, ref int c)
  307.         {
  308.             string inputName;
  309.             int yrLvl, sNum, inProg;
  310.             Console.Write("Enter name: ");
  311.             inputName = Console.ReadLine();
  312.             for (int i = 0; i < ca.Count; i++)
  313.             {
  314.                 Console.Write("[{0}] {1} ", i, ca[i].CourseProgram);
  315.             }
  316.             Console.Write("\nEnter program: ");
  317.             inProg = int.Parse(Console.ReadLine());
  318.             Console.Write("Enter year level: ");
  319.             yrLvl = int.Parse(Console.ReadLine());
  320.             sNum = ((DateTime.Now.Year) * 1000) + (++c);
  321.             s.Add(new Student() { Name = inputName, CourseProgram = ca[inProg].CourseProgram, CPNum = inProg, YearLevel = yrLvl, StudentId = sNum, Courses = new List<Course>(), Payment = new Payment() });
  322.             Console.Write("Student added.");
  323.         }
  324.         static void ViewStudentInfo(List<Student> students)
  325.         {
  326.             FileStream file = new FileStream(@"studentlist.txt", FileMode.Create, FileAccess.Write);
  327.             StreamWriter writer = new StreamWriter(file);
  328.  
  329.             Console.Clear();
  330.             Console.WriteLine("List of Students: ");
  331.             writer.WriteLine("List of Students: ");
  332.             Console.WriteLine(("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  333.             writer.WriteLine(("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  334.             foreach (var stud in students)
  335.             {
  336.                 Console.WriteLine("{0}\t{1}\t{2}\t{3}", stud.Name.PadRight(36), Convert.ToString(stud.StudentId).PadRight(10),
  337.                     Convert.ToString(stud.YearLevel).PadRight(10), stud.CourseProgram.PadRight(8));
  338.                 writer.WriteLine("{0}\t{1}\t{2}\t{3}", stud.Name.PadRight(36), Convert.ToString(stud.StudentId).PadRight(10),
  339.                     Convert.ToString(stud.YearLevel).PadRight(10), stud.CourseProgram.PadRight(8));
  340.             }
  341.  
  342.             writer.Close();
  343.             file.Close();
  344.         }
  345.         static void ShowCourses(List<Course> courses, List<Curriculum> curricula)
  346.         {
  347.             Console.WriteLine("Available Courses: ");
  348.             for (int i = 0; i < courses.Count; i++)
  349.                 Console.WriteLine("[{0}] {1} - {2}", i, courses[i].CourseCode, courses[i].CourseName);
  350.         }
  351.         static void ViewCurriculum(List<Student> students, List<Curriculum> curricula, ref int sn, ref int co)
  352.         {
  353.             sn = EnterStudentID(students);
  354.             if (sn == 0)
  355.                 return;
  356.  
  357.             co = 0;
  358.             for (int i = 0; i < students.Count; i++)
  359.             {
  360.                 if (students[i].StudentId == sn)
  361.                 {
  362.                     break;
  363.                 }
  364.                 co++;
  365.             }
  366.  
  367.             Console.WriteLine("Available Courses: ");
  368.             for (int i = 0; i < curricula[students[co].CPNum].Courses.Count; i++)
  369.                 Console.WriteLine("[{0}] {1} - {2}", i, curricula[students[co].CPNum].Courses[i].CourseCode, curricula[students[co].CPNum].Courses[i].CourseName);
  370.         }
  371.         static void EnrollInCourse(List<Student> students, List<Course> courses, List<Curriculum> curricula, ref int sn, ref int co)
  372.         {
  373.             ViewCurriculum(students, curricula, ref sn, ref co);
  374.             if (sn == 0)
  375.                 return;
  376.  
  377.             Console.Write("Enter course: ");
  378.             int selectedCourse = int.Parse(Console.ReadLine());
  379.             bool check1 = true;
  380.             co = 0;
  381.             for (int i = 0; i < curricula[students[co].CPNum].Courses[selectedCourse].Students.Count; i++)
  382.             {
  383.                 if (sn == curricula[students[co].CPNum].Courses[selectedCourse].Students[i].StudentId)
  384.                 {
  385.                     Console.WriteLine("Student is already enrolled in this course!");
  386.                     check1 = false;
  387.                     return;
  388.                 }
  389.             }
  390.             if (check1 == true)
  391.             {
  392.                 for (int i = 0; i < students.Count; i++)
  393.                 {
  394.                     if (students[i].StudentId == sn)
  395.                     {
  396.                         break;
  397.                     }
  398.                     co++;
  399.                 }
  400.                 students[co].Payment.TotalPayable += courses[selectedCourse].CourseCost;
  401.                 students[co].Payment.Balance += courses[selectedCourse].CourseCost;
  402.                 curricula[students[co].CPNum].Courses[selectedCourse].Students.Add(students[co]); // <-- Fix this
  403.                 students[co].Courses.Add(curricula[students[co].CPNum].Courses[selectedCourse]);  // <-- Keep this
  404.                 Console.WriteLine("Course added.!");
  405.             }
  406.         }
  407.         static void ShowClassList(List<Course> courses, List<Curriculum> curricula)
  408.         {
  409.             FileStream file = new FileStream(@"classlist.txt", FileMode.Create, FileAccess.Write);
  410.             StreamWriter writer = new StreamWriter(file);
  411.  
  412.             Console.Clear();
  413.             ShowCourses(courses, curricula);
  414.             Console.Write("Enter course: ");
  415.             int selectedCourse = int.Parse(Console.ReadLine());
  416.             Console.WriteLine("Class List");
  417.             writer.WriteLine("Class List");
  418.             Console.WriteLine("{0}: {1}", courses[selectedCourse].CourseCode, courses[selectedCourse].CourseName);
  419.             writer.WriteLine("{0}: {1}", courses[selectedCourse].CourseCode, courses[selectedCourse].CourseName);
  420.             Console.WriteLine(("No.").PadLeft(4) + "\t" + ("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  421.             writer.WriteLine(("No.").PadLeft(4) + "\t" + ("Name").PadRight(36) + "\t" + ("StudentNumber").PadRight(10) + "\t" + ("YearLevel").PadRight(10) + "\t" + ("CourseProgram").PadRight(8));
  422.             int count = 1;
  423.             foreach (var st in courses[selectedCourse].Students)
  424.             {
  425.                 Console.WriteLine("[{4}]\t{0}\t{1}\t{2}\t{3}", st.Name.PadRight(36), Convert.ToString(st.StudentId).PadRight(10),
  426.                     Convert.ToString(st.YearLevel).PadRight(10), st.CourseProgram.PadRight(8), Convert.ToString(count).PadLeft(2, '0'));
  427.                 writer.WriteLine("[{4}]\t{0}\t{1}\t{2}\t{3}", st.Name.PadRight(36), Convert.ToString(st.StudentId).PadRight(10),
  428.                     Convert.ToString(st.YearLevel).PadRight(10), st.CourseProgram.PadRight(8), Convert.ToString(count).PadLeft(2, '0'));
  429.                 count++;
  430.             }
  431.             writer.Close();
  432.             file.Close();
  433.         }
  434.         static void ViewEnrolledClasses(List<Student> students)
  435.         {
  436.             int enterStudID = EnterStudentID(students);
  437.             if (enterStudID == 0)
  438.                 return;
  439.  
  440.             int count = 0;
  441.             for (int i = 0; i < students.Count; i++)
  442.             {
  443.                 if (students[i].StudentId == enterStudID)
  444.                 {
  445.                     break;
  446.                 }
  447.                 count++;
  448.             }
  449.  
  450.             Console.WriteLine("Enrolled in: ");
  451.             foreach (var s in students[count].Courses)
  452.                 Console.WriteLine("{0} - {1}", s.CourseCode, s.CourseName);
  453.  
  454.         }
  455.         static void ViewPaymentInfo(List<Student> students)
  456.         {
  457.             FileStream file = new FileStream(@"ecm.txt", FileMode.Create, FileAccess.Write);
  458.             StreamWriter writer = new StreamWriter(file);
  459.  
  460.             int enterStudID = EnterStudentID(students);
  461.             if (enterStudID == 0)
  462.                 return;
  463.  
  464.             int count = 0;
  465.             for (int i = 0; i < students.Count; i++)
  466.             {
  467.                 if (students[i].StudentId == enterStudID)
  468.                 {
  469.                     break;
  470.                 }
  471.                 count++;
  472.             }
  473.  
  474.             writer.WriteLine("Certificate of Matriculation");
  475.             writer.WriteLine("Name: {0} \t ID: {1} \t Program: {2} \t Year: {3}",
  476.                 students[count].Name, students[count].StudentId, students[count].CourseProgram, students[count].YearLevel);
  477.  
  478.             Console.WriteLine("Enrolled in: ");
  479.             foreach (var s in students[count].Courses)
  480.             {
  481.                 Console.WriteLine("{0} - {1} - {2}", s.CourseCode, s.CourseName, s.CourseCost);
  482.                 writer.WriteLine("{0} - {1} - {2}", s.CourseCode, s.CourseName, s.CourseCost);
  483.             }
  484.             Console.WriteLine("Total amount payable: {0}", students[count].Payment.TotalPayable);
  485.             writer.WriteLine("Total amount payable: {0}", students[count].Payment.TotalPayable);
  486.             Console.WriteLine("Total Amount Balance left: {0}", students[count].Payment.Balance);
  487.  
  488.             writer.Close();
  489.             file.Close();
  490.         }
  491.         static void PayBalances(List<Student> students)
  492.         {
  493.             FileStream file = new FileStream(@"receipt.txt", FileMode.Create, FileAccess.Write);
  494.             StreamWriter writer = new StreamWriter(file);
  495.  
  496.             double amount = 0, change = 0, topay = 0;
  497.             int enterStudID = EnterStudentID(students);
  498.             if (enterStudID == 0)
  499.                 return;
  500.             int count = 0;
  501.  
  502.             writer.WriteLine("Official Receipt");
  503.  
  504.             for (int i = 0; i < students.Count; i++)
  505.             {
  506.                 if (students[i].StudentId == enterStudID)
  507.                 {
  508.                     break;
  509.                 }
  510.                 count++;
  511.             }
  512.             if (students[count].Payment.Balance <= 0)
  513.             {
  514.                 Console.WriteLine("No balance left!");
  515.                 return;
  516.             }
  517.             else
  518.             {
  519.                 topay = students[count].Payment.Balance;
  520.                 Console.WriteLine("To pay: {0}", topay);
  521.                 Console.Write("Enter Payment: ");
  522.                 amount = int.Parse(Console.ReadLine());
  523.                 writer.WriteLine("Name: {0} \t ID: {1} \t Program: {2} \t Year: {3}",
  524.                     students[count].Name, students[count].StudentId, students[count].CourseProgram, students[count].YearLevel);
  525.                 change = amount - students[count].Payment.Balance;
  526.                 students[count].Payment.Balance -= amount;
  527.                 Console.WriteLine("Amount Paid: " + amount);
  528.                 Console.WriteLine("Change: " + change);
  529.                 writer.WriteLine("Amount Due: " + topay);
  530.                 writer.WriteLine("Amount Paid: " + amount);
  531.                 writer.WriteLine("Change: " + change);
  532.                 if (students[count].Payment.Balance <= 0)
  533.                 {
  534.                     students[count].Payment.Balance = 0;
  535.                     Console.WriteLine("Balance Left: {0}", students[count].Payment.Balance);
  536.                 }
  537.                 else
  538.                 {
  539.                     Console.WriteLine("Balance Left: " + students[count].Payment.Balance);
  540.                 }
  541.             }
  542.  
  543.             writer.Close();
  544.             file.Close();
  545.         }
  546.         static int EnterStudentID(List<Student> students)
  547.         {
  548.             int enterStudID;
  549.             string name = " ";
  550.             int YearLevel = ' ';
  551.             string CourseProgram = " ";
  552.             int studID = ' ';
  553.             char choice = ' ';
  554.             bool check = false;
  555.  
  556.             do
  557.             {
  558.                 Console.Write("Enter Student ID: ");
  559.                 enterStudID = int.Parse(Console.ReadLine());
  560.                 for (int i = 0; i < students.Count; i++)
  561.                 {
  562.                     if (students[i].StudentId == enterStudID)
  563.                     {
  564.                         check = true;
  565.                     }
  566.                 }
  567.                 if (check == false)
  568.                 {
  569.                     Console.WriteLine("Student not found!");
  570.                     Console.Write("Do you want to try again [Y/N]? ");
  571.                     choice = char.Parse(Console.ReadLine());
  572.                 }
  573.                 if (check == true)
  574.                 {
  575.                     break;
  576.                 }
  577.             } while (choice != 'n');
  578.             if (choice == 'n')
  579.                 return 0;
  580.             if (check == true)
  581.             {
  582.                 for (int i = 0; i < students.Count; i++)
  583.                 {
  584.                     if (students[i].StudentId == enterStudID)
  585.                     {
  586.                         studID = enterStudID;
  587.                         name = students[i].Name;
  588.                         YearLevel = students[i].YearLevel;
  589.                         CourseProgram = students[i].CourseProgram;
  590.                         break;
  591.                     }
  592.                 }
  593.                 Console.Clear();
  594.                 Console.WriteLine("Student ID: " + studID);
  595.                 Console.WriteLine("Name: " + name);
  596.                 Console.WriteLine("Year level: " + YearLevel);
  597.                 Console.WriteLine("Course Program: " + CourseProgram);
  598.             }
  599.             return enterStudID;
  600.         }
  601.     }
  602.     public class Student
  603.     {
  604.         public int StudentId { get; set; }
  605.         public string Name { get; set; }
  606.         public int YearLevel { get; set; }
  607.         public string CourseProgram { get; set; }
  608.         public int CPNum { get; set; }
  609.         public List<Course> Courses { get; set; }
  610.         public Payment Payment { get; set; }
  611.     }
  612.     public class Course
  613.     {
  614.         public string CourseCode { get; set; }
  615.         public string CourseName { get; set; }
  616.         public double CourseCost { get; set; }
  617.         public List<Student> Students { get; set; }
  618.     }
  619.     public class Curriculum
  620.     {
  621.         public string CourseProgram { get; set; }
  622.         public List<Course> Courses { get; set; }
  623.     }
  624.     public class Payment : Student
  625.     {
  626.         private double TotalAmountPayable { get; set; }
  627.         private double BalanceLeft { get; set; }
  628.  
  629.         public double TotalPayable
  630.         {
  631.             get
  632.             {
  633.                 return TotalAmountPayable;
  634.             }
  635.             set
  636.             {
  637.                 TotalAmountPayable = value;
  638.             }
  639.         }
  640.         public double Balance
  641.         {
  642.             get
  643.             {
  644.                 return BalanceLeft;
  645.             }
  646.             set
  647.             {
  648.                 BalanceLeft = value;
  649.             }
  650.  
  651.         }
  652.     }
  653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement