




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Advanced Programming (1651) - ASM 2 - Grade D
Typology: Study Guides, Projects, Research
1 / 106
This page cannot be seen from the preview
Don't miss anything!





























































































Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Phan Nhat Linh^ Student ID GCD Class GCD0905 Assessor name Pham Thanh Son Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature Linh Grading grid P3 P4 M3 M4 D3 D
Grade: Assessor Signature: Date: Lecturer Signature:
**I/ BUILD AN APPLICATION DERIVED FROM UML CLASS DIAGRAMS (P3 – M3)
Figure 1 : Scenario The client is the director of the Da Nang Department of Education. They wanted to create a program to help all schools in the city easily manage students and teachers of each school. The program includes basic tasks such as CRUD and other functions such as searching and sorting. So I was assigned to do this project, I chose C# language and wrote it object-oriented for easy code management, maintenance and application development easily. Below is the design of the program that I am working on.
When adding object information, incorrect data entry is common. With that problem, we have designed for users to have the function of updating object information by ID. Many users may find the function of updating information to be tedious, preferring instead to remove and add new information. We will not let our users down, thus the ability to remove items has been introduced to this software. This function will also assist the user in deleting an item that is no longer associated with the list. The list of objects has a lot of information, many objects display in tables, there are hundreds or even thousands of rows. So it's really difficult to find an object that I want to see. So we created this program a search function, users can search by ID or search by Name depending on their preferences or information they already have. Filtering on object components is indeed a convenience for users to easily separate object types appropriately. The program can filter students by grade and filter by rating. Lecturer will have the function of filtering by years of experience and rating. To help users manage and see which students have the highest and lowest scores, we have built a function to sort the list of students by scores from smallest to largest. In addition, the function of sorting teachers based on the number of years of experience is also included in the program, helping users to compile teacher information to match the salary and bonus depending on the number of years of dedication to the school. The function to sort alphabetically from a-z is also included in most programs and this program is no exception. Finally, the reset list function is used to recreate a new data for new information. For example, at the end of the school year, students will be promoted and the new class will have to have new data.
Figure 3 : Class Diagram Explanation: This is a manager's development system. Create a system that can manage students as well as lecturer. When users first launch the app, they will have the option of viewing the student or lecturer management screens. The administration has the ability to add, update, delete, and perform query tasks such as searching, sort and reset list. Then we'll be able to see what we've changed. This can be viewed as a solution that simplifies management. Class Program: This is the main class used to run the program and execute statements. This class includes functions to perform add, edit, delete, search, filter, sort, and reset tasks for specified objects. Class person: This can be seen as the core layer of the program. This class contains private fields id , name , age are information of a person and getter , setter are properties. It has 2 constructors namely constructor with no parameters and constructor with 3 parameters. The public methods in this class are DisplayInformation() and DisplayInformationWhenSearchOrFilter() to display a person's information in a different format to suit each case. Class Student: The Student class inherits from the Person class. This class is for creating student objects. In addition to the properties inherited from the parent class id, name, and age, the Student class also has a private field of grade and gradeStrategy. There are 3 constructors appearing in this class including
Design pattern (Strategy pattern): According to the strategy pattern, we must create a class called strategies for each algorithm (FailStrategy, PassStrategy, MeritStrategy, DistinctionStrategy). This algorithm's code will replace the hardwired code with a reference to IGradeStrategy. That part of the code will not need to know the specifics of the strategy it employs; it can use any strategy with the interface provided by the strategy. Then the student class will have a field that is an IGradeStrategy object and implement the method in that object. Using the Strategy design pattern, we customized instructor experience assessment via the IExperienceStrategy Interface. Juniorstrategy, MiddleStrategy, and SeniorStrategy will all use IExperienceStrategy. This enables the program to be more flexible in assessing instructor experience. The interface defines the function RatingExprience(), which is overridden in the implementing classes to return a string containing information evaluating the teacher's experience over years of experience. Because the information about the teacher experience assessment can be changed flexibly over time, it aids in the creation of the lecturer object.
2. Implementation
In this part, I am going to show the code of my program corresponding to the above class diagrams. Class Person Figure 4 : Class Person (UML)
Figure 5 : Class Person (Code) The Person class includes the person's information id, name and age. These fields are all private, so to get and assign data to these fields, we have to go through the properties Id, Name and Age. Id and Name are strings so we don't need to worry too much when assigning data to them. However, when assigning data to Age with data type of interger, we must perform validation to avoid the program crashing. If the user assigns Age a value greater than 100 or less than 6, the program will throw an Exception so that the program prints out to the user that there is a message " Age must be from 6 to 100 ". We can assign data to objects using constructors. This class consists of 2 constructors, a constructor without parameters and a constructor with 3 parameters. Finally, the methods defined with the virtual keyword for the subclass to override are DisplayInformation(), DisplayInfoWhenSearchOrFilter() and AddRowTable(ConsoleTable table).
Figure 7 : Class Student (Code) The Student class inherits the Person class, so the Person class fields are id, name, and age, in addition, the student class also has two other fields, grade with data type double and gradeStrategy with data type as an interface object IGradeStrategy. Property Grade will do the same thing as getters and setters for the grade field. The point that the program allows the user to enter will be from 0 to 10, so when the user enters this wrong range, the program will give the user a message " Age must be from 0 to 10 ". This class consists of 3 constructors which are the constructor that does not contain parameters, the constructor that contains 1 parameter and the constructor that contains 4 parameters. Below are the
overridden methods from the parent class to display and process information appropriately for an object called Student. There is also a method called GettingGrade() which returns a RatingGrade() method of the gradeStrategy field. Class Lecturer Figure 8 : Class Lecturer (UML)
The last of this class will be the methods that override the parent class, which will print the object's information appropriately. Interface IGradeStrategy, class FailStrategy, class PassStrategy, class MeritStrategy, DistinctionStrategy Figure 10 : Interface IGradeStrategy, class FailStrategy, class PassStrategy, class MeritStrategy, DistinctionStrategy (UML) Figure 11 : Interface IGradeStrategy (code) Figure 12 : Class FailStrategy (code)
Figure 13 : Class PassStrategy (code) Figure 14 : Class MeritStrategy (code) Figure 15 : Class DistinctionStrategy (code) This is the part where we use the Design Pattern in this program. We used the Strategy design pattern to customize student assessment scores through the IGradeStrategy Interface. The Failstrategy, PassStrategy, MeritStrategy, and DistinctionStrategy classes will implement IGradeStrategy. Helps the program to be flexible in assessing student scores. The method RatingGrade() has been defined in the interface and is overridden in the implemented classes, for the purpose of returning a string containing information that is the student's rating through the score. It helps that when initializing the student object, the information about the student's evaluation score will be changed flexibly through the score, in addition, when the program is developed, we can easily add and modify the code. easy because the algorithm will reside in each of these classes and it will be separate from the running program. Interface IExperienceStrategy, class JuniorStrategy, class MiddleStrategy, class SeniorStrategy