Advanced Programming (1651) - ASM 2 - Grade D, Study Guides, Projects, Research of Advanced Computer Programming

Advanced Programming (1651) - ASM 2 - Grade D

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 06/15/2023

Phan-Nhat-Linh-11
Phan-Nhat-Linh-11 🇻🇳

4.9

(108)

34 documents

1 / 106

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ASSIGNMENT 2 FRONT SHEET
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
GCD201635
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
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Advanced Programming (1651) - ASM 2 - Grade D and more Study Guides, Projects, Research Advanced Computer Programming in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

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

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Table of Contents

  • I/ BUILD AN APPLICATION DERIVED FROM UML CLASS DIAGRAMS (P3 – M3)
      1. Scenario analysis
      • 1.1 Scenario
      • 1.2 Use-case Diagram
      • 1.3 Class Diagram and Explanation
      1. Implementation
      • 2.1 Code
      • 2.2 Program screenshots
      • 2 .3 Test Plan
  • II/ DISCUSSION (P4 – M4 – D3 – D4 )
    • pattern types (P4) 1. Discuss a range of design patterns with relevant examples of creational, structural and behavioral
      • 1.1 Creational Design Pattern
      • 1.2 Structural Design Patterns..............................................................................................................
      • 1.3 Behavioral Design Patterns
      1. Reconcile the most appropriate design pattern from a range with a series of given scenarios (M4)
      • 2.1 Benefit of Strategy design pattern
      • 2.2 Differences of Strategy design pattern and other design patterns
      • 2.3 Why I choose Strategy design pattern to develop scenario?
      1. Evaluate the use of design patterns for the given purpose specified (D3)
    • of your choices (D4).................................................................................................................................. 4. Critically evaluate a range of design patterns against the range of given scenarios with justification
      • 4.1 Factory pattern
      • 4.2 Builder Pattern
      • 4.3 Strategy design pattern (I used in the scenario)
  • References
  • Figure 1: Scenario Table of Figures
  • Figure 2: Use-case Diagram
  • Figure 3: Class Diagram
  • Figure 4: Class Person (UML)
  • Figure 5: Class Person (Code)
  • Figure 6: Class Student (UML)
  • Figure 7: Class Student (Code)
  • Figure 8: Class Lecturer (UML)
  • Figure 9: Class Lecturer (Code)
  • DistinctionStrategy (UML) Figure 10: Interface IGradeStrategy, class FailStrategy, class PassStrategy, class MeritStrategy,
  • 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)
  • (UML) Figure 16: Interface IExperienceStrategy, class JuniorStrategy, class MiddleStrategy, class SeniorStrategy
  • Figure 17: Interface IExperienceStrategy (code)
  • Figure 18 : Class JuniorStrategy (Code)
  • Figure 19: Class MiddleStrategy (Code)
  • Figure 20: Class SeniorStrategy (Code)
  • Figure 21: Class Program (UML)
  • Figure 22: Main method
  • Figure 23: StudentMenu method
  • Figure 24: LecturerMenu method
  • Figure 25: Create method (1)
  • Figure 26: Create method (2)
  • Figure 27: Update method (1)
  • Figure 28: Update method (2)
  • Figure 29: Delete method
  • Figure 30: Search method
  • Figure 31: Filter method
  • Figure 32: Sort method (1)
  • Figure 33: Sort method (2)
  • Figure 34: Reset method
  • Figure 35: Other function ( RemoveSpace, checkIDExist)
  • Figure 36: Other function ( GetObjectById, GetChoiceLevel2, checkNameExist, GetObjectByName)
  • Figure 37: Other function (FilterByGrade, FilterByYear, FilterByRating)
  • Figure 38: Main menu (interface)
  • Figure 39: Student menu (interface)
  • Figure 40: Add function (student)
  • Figure 41: Update function (student)...........................................................................................................
  • Figure 42: Delete function (student)
  • Figure 43: Search by ID function (student)
  • Figure 44: Search by Name function (student)
  • Figure 45: Filter by grade function (student)
  • Figure 46: Filter by rating function (student)
  • Figure 47: Sort by name function (student)
  • Figure 48: Reset list function (student)
  • Figure 49: Lecturer menu
  • Figure 50: Add function (Lecturer)
  • Figure 51: Update function (Lecturer)..........................................................................................................
  • Figure 52: Delete function (Lecturer)
  • Figure 53: Search by ID (Lecturer)
  • Figure 54: Search by Name (Lecturer)
  • Figure 55: Filter by yearExperience (Lecturer)
  • Figure 56: Filter by rating (Lecturer)
  • Figure 57: Sort by name (Lecturer)
  • Figure 58: Sort by year experience (Lecturer)
  • Figure 59: Reset list (Lecturer)
  • Figure 60: Factory method Design Patterns (UML)
  • Figure 61: Example of Factory method Design Patterns (UML)
  • Figure 62: Implement Factory method Design Patterns in C# (1)
  • Figure 63: Implement Factory method Design Patterns in C# (2)................................................................
  • Figure 64: Adapter Design Patterns (UML)
  • Figure 65: Implement Adapter Design Patterns in C# (1)
  • Figure 66: Implement Adapter Design Patterns in C# (2)
  • Figure 67: Implement Adapter Design Patterns in C# (3)
  • Figure 68: Strategy Design Pattern (UML)....................................................................................................
  • Figure 69: Example of Strategy Design Pattern (UML)
  • Figure 70: Implement Strategy Design Pattern in C# (1)..............................................................................
  • Figure 71: : Implement Strategy Design Pattern in C# (2)............................................................................
  • Figure 72: Class Diagram
  • Figure 73: When use Factory pattern in the scenario (UML)
  • Figure 74: When use Factory pattern in the scenario (1)
  • Figure 75: When use Factory pattern in the scenario (2)
  • Figure 76: When use Factory pattern in the scenario (3)
  • Figure 77: When use Factory pattern in the scenario (4)
  • Figure 78: When use Builder pattern in the scenario (UML)
  • Figure 79: When use Builder pattern in the scenario (1)
  • Figure 80: When use Builder pattern in the scenario (2)
  • Figure 81: When use Builder pattern in the scenario (3)
  • Figure 82: When use Builder pattern in the scenario (4)
  • Figure 83: I used Strategy pattern in the scenario (1)
  • Figure 84: I used Strategy pattern in the scenario (2)

**I/ BUILD AN APPLICATION DERIVED FROM UML CLASS DIAGRAMS (P3 – M3)

  1. Scenario analysis**

1.1 Scenario

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.

1.3 Class Diagram and Explanation

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

2.1 Code

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