Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.41 KB | None | 0 0
  1. Skip to content
  2. This repository
  3. Search
  4. Pull requests
  5. Issues
  6. Gist
  7. @TsukishirOSan
  8. Unwatch 1
  9. Star 0
  10. Fork 0 TsukishirOSan/ModuleFive
  11. Branch: master ModuleFive/CreateClassesInfo.cs
  12. @TsukishirOSanTsukishirOSan 12 days ago Module Five
  13. 1 contributor
  14. RawBlameHistory 689 lines (601 sloc) 21.1 KB
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. /**
  21. * Module Five Assignment
  22. In this assignment, you need to convert your objects for the application into class files. Create a class file for:
  23. A Student
  24. A Teacher
  25. A UProgram (C# uses Program as the name of the class that contains Main() so we must use a different class name here)
  26. A Degree
  27. A Course
  28. Transfer the variables you created in Module 1 into these class files. Ensure that you encapsulate
  29. your member variables in the class files using properties.
  30. The Course object should contain
  31. * an array of Student objects so ensure that you create
  32. * an array inside the Course object to hold Students as well as
  33. * an array to contain Teacher objects as each course may have more than one teacher or TAs.
  34.  
  35. For this assignment,
  36. * create arrays of size 3 for students and the same for teachers.
  37. * The UProgram object should be able to contain degrees and the degrees should be able to contain courses
  38. as well but for the purposes of this assignment,
  39. * just ensure you have a single variable in UProgram to hold
  40. a Degree and single variable in Degree to hold a Course.
  41. Use this diagram as an example of how the objects relate to each other.
  42. Class diagram showing the Program, Degree, Course, Student, and Teacher classes in a hiearchy where
  43. a Program is at the top, and contains Degrees which in turn contain Courses, which include students and teachers.
  44. --Add a static class variable to the Student class to track the number of students currently enrolled in a school.
  45. --Increment a student object count every time a Student is created.
  46. *In the Main() method of Program.cs:
  47. --Instantiate three Student objects.
  48. --Instantiate a Course object called Programming with C#.
  49. --Add your three students to this Course object.
  50. --Instantiate at least one Teacher object.
  51. --Add that Teacher object to your Course object
  52. --Instantiate a Degree object, such as Bachelor.
  53. --Add your Course object to the Degree object.
  54. --Instantiate a UProgram object called Information Technology.
  55. --Add the Degree object to the UProgram object.
  56. --Using Console.WriteLine statements, output the following information to the console window:
  57. --The name of the program and the degree it contains
  58. --The name of the course in the degree
  59. --The count of the number of students in the course.
  60. --Your output should look similar to this:
  61. Console window showing the output from the program code
  62. * */
  63.  
  64.  
  65. namespace ModuleFive
  66. {
  67. class CreateClassesInfo
  68. {
  69. static void Main(string[] args)
  70. {
  71.  
  72.  
  73. var student1 = new Student("Faïza", "Harbi", "faiza.harbi@mic.edu", new DateTime(1982, 3, 6), "797 code Avenue",
  74. "Residence bar", "Montpellier", "Hérault", "34070", "FRANCE", 'F', 3.9f, 100.02m, 4);
  75. List<Student> students = new List<Student>();
  76. students.Add(student1);
  77.  
  78. var student2 = new Student("Ivan", "Joule", "ivan.joule@foo.edu", new DateTime(1982, 9, 24), "2 Main Street",
  79. "", "Stropia", "", "0407", "MACEDONIA", 'M', 3.8f, 500.60m, 3);
  80. students.Add(student2);
  81.  
  82. var student3 = new Student("Ana", "Blake", "ana.blake@foo.edu", new DateTime(1989, 4, 17), "24 Bazinga Road", "Residence Cooper", "Moscow", "", "101000", "RUSSIA",
  83. 'F', 3.9f, 300.20m, 3);
  84. students.Add(student3);
  85.  
  86. int c = Student.Counter;
  87.  
  88. var teacher1 = new Teacher("Julien", "Mazet", "julien.mazet@cs.mic.edu", new DateTime(1981, 3, 7), "33 Oxford Street",
  89. "Building 50", "Cambridge", "MA", "3143",
  90. "USA", 'M', "Computer Science DEV204", 80);
  91.  
  92. var teachers = new List<Teacher>();
  93. teachers.Add(teacher1);
  94.  
  95. var course1 = new Course("Programming with C#", "Computer Science DEV204", 80);
  96. var courses = new List<Course>();
  97. courses.Add(course1);
  98.  
  99. var degree1 = new Degree("Bachelor Of Science", "Computer Science", 80, courses);
  100. var degrees = new List<Degree>();
  101. degrees.Add(degree1);
  102.  
  103. var uprogram1 = new UProgram("Information Technology", "Dean Winchester", degrees);
  104.  
  105. WriteProgramInfo(uprogram1, courses);
  106. Console.WriteLine("Press a key to continue.....");
  107. Console.ReadKey();
  108. }
  109.  
  110. private static void WriteProgramInfo(UProgram uprogram1, List<Course> courses)
  111. {
  112.  
  113. try
  114. {
  115. var deg = uprogram1.UDegreesProposed.First();
  116. var crse = courses.First().Cname;
  117. Console.WriteLine("The {0} contains the {1} degree.{2}", uprogram1.Uname, deg.Dname, Environment.NewLine);
  118. Console.WriteLine("The {0} degree contains the course {1}.{2}", deg.Dname, crse, Environment.NewLine);
  119. Console.WriteLine("The {0} course contains {1} student(s).{2}", crse, Student.Counter, Environment.NewLine);
  120. }
  121. catch (InvalidOperationException ioe)
  122. {
  123. Console.WriteLine("Invalid type operation", ioe.Message);
  124. }
  125. catch (ArgumentNullException ane)
  126. {
  127. Console.WriteLine("No input", ane.Message);
  128. }
  129. }
  130.  
  131. #region dedicated to the abstract class Person inherited by the classes Student and Teacher
  132. abstract internal class Person
  133. {
  134.  
  135. // this is the type of the encapsulated getter setter related to the first name
  136. private string first;
  137. public string First
  138. {
  139. get
  140. {
  141. return first;
  142. }
  143. set
  144. {
  145. if(value != null)
  146. first = value;
  147. }
  148. }
  149.  
  150. // this is the type of the encapsulated getter setter related to the last name same for below
  151. private string last;
  152. public string Last
  153. {
  154. get
  155. {
  156. return last;
  157. }
  158. set
  159. {
  160. if(value != null)
  161. last = value;
  162. }
  163. }
  164.  
  165. private string email;
  166. public string Email
  167. {
  168. get
  169. {
  170. return email;
  171. }
  172. set
  173. {
  174. if(value != null)
  175. email = value;
  176. }
  177. }
  178.  
  179. private DateTime birthdate;
  180.  
  181. public DateTime Birthdate
  182. {
  183. get
  184. {
  185. return birthdate;
  186. }
  187.  
  188. private set
  189. {
  190. if(value != null)
  191. birthdate = value;
  192. }
  193. }
  194.  
  195.  
  196. private string addressLine1;
  197. public string AddressLine1
  198. {
  199. get
  200. {
  201. return addressLine1;
  202. }
  203. set
  204. {
  205. if(value != null)
  206. addressLine1 = value;
  207. }
  208. }
  209.  
  210. private string addressLine2;
  211. public string AddressLine2
  212. {
  213. get
  214. {
  215. return addressLine2;
  216. }
  217. set
  218. {
  219. if(value != null)
  220. addressLine2 = value;
  221. }
  222. }
  223.  
  224. private string city;
  225. public string City
  226. {
  227. get
  228. {
  229. return city;
  230. }
  231. private set
  232. {
  233. if(value != null)
  234. city = value;
  235. }
  236. }
  237.  
  238. private string stateOrProvince;
  239. public string StateOrProvince
  240. {
  241. get
  242. {
  243. return stateOrProvince;
  244. }
  245. set
  246. {
  247. if(value != null)
  248. stateOrProvince = value;
  249. }
  250. }
  251.  
  252. private string zipPostal;
  253. public string ZipPostal
  254. {
  255. get
  256. {
  257. return zipPostal;
  258. }
  259. set
  260. {
  261. if(value != null)
  262. zipPostal = value;
  263. }
  264. }
  265.  
  266. private string country;
  267. public string Country
  268. {
  269. get
  270. {
  271. return country;
  272. }
  273. set
  274. {
  275. if(value != null)
  276. country = value;
  277. }
  278. }
  279.  
  280. private char gender;
  281. public char Gender
  282. {
  283. get
  284. {
  285. return gender;
  286. }
  287. set
  288. {
  289. if(value != '\0')
  290. gender = value;
  291. }
  292. }
  293.  
  294. internal Person(string first, string last, string email, DateTime birthdate, string addressLine1,
  295. string addressLine2, string city, string stateOrProvince, string zipPostal,
  296. string country, char gender)
  297. {
  298. this.First = first;
  299. this.Last = last;
  300. this.Email = email;
  301. this.Birthdate = birthdate;
  302. this.AddressLine1 = addressLine1;
  303. this.AddressLine2 = addressLine2;
  304. this.City = city;
  305. this.StateOrProvince = stateOrProvince;
  306. this.ZipPostal = zipPostal;
  307. this.Country = country;
  308. this.Gender = gender;
  309. }
  310.  
  311. public override string ToString()
  312. {
  313. return String.Format("{0}{1} {2}",Environment.NewLine, First, Last);
  314. }
  315.  
  316.  
  317. }
  318. #endregion
  319. //create and initialize the number of students counter
  320. #region dedicated to the class Student
  321. internal class Student: Person
  322. {
  323. private static int counter = 0;
  324. public static int Counter
  325. {
  326. get
  327. {
  328. return counter;
  329. }
  330. set
  331. {
  332. counter = value;
  333. }
  334. }
  335.  
  336. private float OverallGPA;
  337. public float overallGPA
  338. {
  339. get
  340. {
  341. return OverallGPA;
  342. }
  343. set
  344. {
  345. if(value > 0.0)
  346. OverallGPA = value;
  347. }
  348. }
  349.  
  350. private Decimal AccountBalance;
  351. public Decimal accountBalance
  352. {
  353. get
  354. {
  355. return AccountBalance;
  356. }
  357. set
  358. {
  359. AccountBalance = value;
  360. }
  361. }
  362.  
  363. private int NumCoursesTaken;
  364. public int numCoursesTaken
  365. {
  366. get
  367. {
  368. return NumCoursesTaken;
  369. }
  370. set
  371. {
  372. if(value >= 0)
  373. this.NumCoursesTaken = value;
  374. }
  375. }
  376.  
  377. internal Student(string first, string last, string email, DateTime birthdate, string addressLine1,
  378. string addressLine2, string city, string stateOrProvince, string zipPostal,
  379. string country, char gender, float overallGPA, Decimal accountBalance, int numCoursesTaken)
  380. : base(first, last, email, birthdate, addressLine1, addressLine2, city, stateOrProvince,
  381. zipPostal, country, gender)
  382. {
  383. this.AccountBalance = accountBalance;
  384. this.OverallGPA = overallGPA;
  385. this.NumCoursesTaken = numCoursesTaken;
  386. // increment the number of Student instanciated
  387. counter++;
  388. }
  389.  
  390.  
  391. // override methode to output the proper fields according the class being handled
  392. public override string ToString()
  393. {
  394. return String.Format(
  395. "email: {0}{1}" +
  396. "Address {2}{1}" + "{3}{1}" +
  397. "{4}, {5}{1}" +
  398. "{6}, {7}{1}{1}" +
  399. "------------{1}" +
  400. "Overall GPA: {8}{1}" +
  401. "Account Balance: {9}{1}" +
  402. "Gender: {10}{1}" +
  403. "Number of courses taken: {11}{1}"+
  404. "{1}Courses taken: {12}{1}{1}",
  405. Email, Environment.NewLine, AddressLine1, AddressLine2, City, StateOrProvince, ZipPostal, Country,
  406. overallGPA, accountBalance, Gender, numCoursesTaken
  407. );
  408. }
  409. }
  410. #endregion
  411.  
  412. #region Dedicated to the class Teacher
  413. internal class Teacher: Person
  414. {
  415. private string pField;
  416. public string Pfield
  417. {
  418. get
  419. {
  420. return pField;
  421. }
  422. set
  423. {
  424. if(value != null)
  425. pField = value;
  426. }
  427. }
  428.  
  429. private int pNumOfCourses;
  430. public int PnumOfCourses
  431. {
  432. get
  433. {
  434. return pNumOfCourses;
  435. }
  436. set
  437. {
  438. if(value > 0)
  439. pNumOfCourses = value;
  440. }
  441. }
  442.  
  443. internal Teacher(string first, string last, string email, DateTime birthdate, string addressLine1,
  444. string addressLine2, string city, string stateOrProvince, string zipPostal,
  445. string country, char gender, string pField, int pNumOfCourses)
  446. : base(first, last, email, birthdate, addressLine1, addressLine2, city, stateOrProvince,
  447. zipPostal, country, gender)
  448. {
  449. this.Pfield = pField;
  450. this.PnumOfCourses = pNumOfCourses;
  451. }
  452.  
  453. }
  454. #endregion
  455.  
  456. #region Dedicated to the class Course
  457. internal class Course
  458. {
  459. private string cName; // i.e. "DEV204x"
  460. public string Cname
  461. {
  462. get
  463. {
  464. return cName;
  465. }
  466. set
  467. {
  468. if(value != null)
  469. cName = value;
  470. }
  471. }
  472.  
  473. private string cField; // i.e. "Computer Science and Programming; Data processing"
  474. public string Cfield
  475. {
  476. get
  477. {
  478. return cField;
  479. }
  480. set
  481. {
  482. if(value != null)
  483. cField = value;
  484. }
  485. }
  486.  
  487. private int cCredits;
  488. public int Ccredits
  489. {
  490. get
  491. {
  492. return cCredits;
  493. }
  494. set
  495. {
  496. if(value > 0)
  497. cCredits = value;
  498. }
  499. }
  500.  
  501. private List<Student> studentsArray = new List<Student>();
  502.  
  503. public List<Student> getStudsList()
  504. {
  505. return studentsArray;
  506. }
  507.  
  508. public void setStudsList(List<Student> studentsArray)
  509. {
  510. this.studentsArray = studentsArray;
  511. }
  512.  
  513.  
  514. private List<Teacher> professorsArray = new List<Teacher>();
  515.  
  516. public List<Teacher> getProfList()
  517. {
  518. return professorsArray;
  519. }
  520.  
  521. public void setProfList(List<Teacher> professorsArray)
  522. {
  523. this.professorsArray = professorsArray;
  524. }
  525.  
  526. internal Course(string cName, string cField, int cCredits)
  527. {
  528. this.Cname = cName;
  529. this.Cfield = cField;
  530. this.Ccredits = cCredits;
  531. }
  532.  
  533. public void addStudentToStudentsArray(Student student)
  534. {
  535. studentsArray.Add(student);
  536. }
  537.  
  538. public void addProfessorToProfessorsArray(Teacher teacher)
  539. {
  540. professorsArray.Add(teacher);
  541. }
  542.  
  543.  
  544. /*public override string ToString()
  545. {
  546. return String.Format("{0}Course's name: {1}"+"{0}Course's Field: {2}"+"{0}Number of credits needed: {3}", Environment.NewLine,
  547. Cname, Cfield, Ccredits);
  548. }*/
  549. }
  550. #endregion
  551.  
  552. #region Dedicated to the class Degree
  553. internal class Degree
  554. {
  555. private string dName;
  556. public string Dname
  557. {
  558. get
  559. {
  560. return dName;
  561. }
  562. set
  563. {
  564. if(value != null)
  565. dName = value;
  566. }
  567. }
  568.  
  569. private string dField;
  570. public string Dfield
  571. {
  572. get
  573. {
  574. return dField;
  575. }
  576. set
  577. {
  578. if(value != null)
  579. dField = value;
  580. }
  581. }
  582.  
  583. private int dCredits;
  584. public int Dcredits
  585. {
  586. get
  587. {
  588. return dCredits;
  589. }
  590. set
  591. {
  592. if(value >= 0)
  593. dCredits = value;
  594. }
  595. }
  596.  
  597. private List<Course> dCourses = new List<Course>();
  598. public List<Course> Dcourses = new List<Course>();
  599.  
  600. public List<Course> getCourseList()
  601. {
  602. return Dcourses;
  603. }
  604. public void setCourseList(List<Course> dCourses)
  605. {
  606. if(dCourses != null)
  607. this.Dcourses = dCourses;
  608. }
  609.  
  610.  
  611. internal Degree(string dName, string dField, int dCredits, List<Course> dCourses)
  612. {
  613. this.Dname = dName;
  614. this.Dfield = dField;
  615. this.Dcredits = dCredits;
  616. this.Dcourses = getCourseList();
  617. }
  618.  
  619. public void addCourseToDegree(Course course)
  620. {
  621. Dcourses.Add(course);
  622. }
  623.  
  624. /* public override string ToString()
  625. {
  626. return String.Format("{0}Name of the degree: {1}" + "{0}Degree's field: {2}"+
  627. "{0}Number of credits needed: {3}"+"{0}List Of Courses: {4}", Environment.NewLine, Dname, Dfield, Dcredits, Dcourses);
  628. }*/
  629.  
  630. }
  631. #endregion
  632.  
  633. #region Dedicated to the class UProgram
  634. internal class UProgram
  635. {
  636. private string uName;
  637. public string Uname
  638. {
  639. get
  640. {
  641. return uName;
  642. }
  643. set
  644. {
  645. if(value != null)
  646. uName = value;
  647. }
  648. }
  649.  
  650. private string uDean;
  651. public string Udean
  652. {
  653. get
  654. {
  655. return uDean;
  656. }
  657. set
  658. {
  659. if(value != null)
  660. uDean = value;
  661. }
  662. }
  663.  
  664. private List<Degree> uDegreesProposed = new List<Degree>();
  665. public List<Degree> UDegreesProposed = new List<Degree>();
  666. List<Degree> getUDegreesProposed()
  667. {
  668. return uDegreesProposed;
  669. }
  670.  
  671. public void setUDegrees(Degree degree)
  672. {
  673. UDegreesProposed.Add(degree);
  674. }
  675.  
  676. public UProgram(string uName, string uDean, List<Degree> uDegreesProposed)
  677. {
  678. this.Uname = uName;
  679. this.Udean = uDean;
  680. this.UDegreesProposed = uDegreesProposed;
  681. }
  682.  
  683.  
  684. /*public override string ToString()
  685. {
  686. return String.Format("{0}University name: {1}"+"{0}University Dean: {2}"+
  687. "{0}Degrees available: {3}", Environment.NewLine, Uname, Udean, UDegreesProposed);
  688. }*/
  689. }
  690. #endregion
  691. }
  692.  
  693. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement