This exercise earns Merit points in C programming. This exercise presents design patterns, especially the Strategy pattern, APIE rules in objectoriented programming, exception handling, and error handling.
ASSIGNMENT FRONT SHEET Qualification BTEC Level HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date 26/12/2023 Date Received 1st submission Re-submission Date 26/12/2023 Date Received 2nd submission Student Name Tran Duc Long Student ID GCH210562 Class GCH1106 Assessor name Le Viet Bach 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 Grading grid P3 P4 M3 M4 D3 D4 Summative Feedback: Resubmission Feedback: 2.1 Grade: Lecturer Signature: Assessor Signature: Date: Table of Contents Introduction Scenario analysis 2.1 Scenario 2.2 Diagram Implementation 10 3.1 Code 10 3.1.1 Tree Code 11 3.1.2 Product Code 14 3.1.3 Fruit Code 15 3.1.4 Medicine Code 16 3.1.5 Wood Code 17 3.1.6 IHarvestStrategy Code 18 3.1.7 FruitHarvestStrategy Code 19 3.1.8 MedicineHarvestStrategy Code 20 3.1.9 WoodHarvestStrategy Code 21 3.1.10 Main menu Code 22 3.1.11 Plant menu Code 25 3.1.12 Harvest menu Code 27 3.1.13 Growth menu Code 29 3.1.14 Validate Code 31 3.1.15 Main program Code 34 3.2 Program screenshots 35 3.2.1 Flow 1: Plants and growth trees 35 3.2.2 Flow 2: Plants and harvest trees 42 Discussion 50 4.1 Range of similar patterns 50 4.2 Usage of pattern 53 Conclusion 54 Table of Figures Figure 1: Tree Class Diagram image Figure 2: Class Library Structure image 10 Figure 3: Console App structure image 11 Figure 4: Tree class code image 12 Figure 5: Tree class constructor image 12 Figure 6: CountTime function image 13 Figure 7: Growing tree methods images 13 Figure 8: GetTreeStatus method image 14 Figure 9: Product abstract class image 14 Figure 10: Fruit class image 15 Figure 11: Medicine class image 16 Figure 12: Wood class image 17 Figure 13: IHarvestStrategy interface image 18 Figure 14: FruitHarvestStrategy class image 19 Figure 15: MedicineHarvestStrategy class image 20 Figure 16: WoodHarvestStrategy class image 21 Figure 17: MainMenu class image 22 Figure 18: MainMenu class methods image 23 Figure 19: MainMenu class methods image 24 Figure 20: PlantMenu class image 25 Figure 21: PlantMenu methods image 26 Figure 22: HarvestMenu methods class image 27 Figure 23: HarvestMenu methods class image 28 Figure 24: GrowthMenu class image 29 Figure 25: GrowthMenu print menu method image 30 Figure 26: Validate class image 31 Figure 27: InputInterger method image 32 Figure 28: InputDouble method image 33 Figure 29: ValidateHarvestAmount method image 34 Figure 30: Program class image 34 Figure 31: Running program Flow image 36 Figure 32: Running program Flow image 36 Figure 33: Running program Flow image 37 Figure 34: Running program Flow image 38 Figure 35: Running program Flow image 38 Figure 36: Running program Flow image 39 Figure 37: Running program Flow image 40 Figure 38: Running program Flow image 41 Figure 39: Running program Flow image 42 Figure 40: Running program Flow image 43 Figure 41: Running program Flow image 44 Figure 42: Running program Flow image 45 Figure 43: Running program Flow image 46 Figure 44: Running program Flow image 47 Figure 45: Running program Flow image 48 Figure 46: Running program Flow image 49 Figure 47: Running program Flow image 50 Introduction This Assignment represents a follow-up to our ongoing investigation of Object-Oriented Programming (OOP) and Design Patterns Our objective is to showcase the utility and efficiency of these concepts in software development by selecting a real-life scenario, creating a class based on a relevant class diagram, and exploring various Design Patterns This process is geared towards equipping us with valuable knowledge and skills that will undoubtedly influence our future pursuits in the realm of software engineering Scenario analysis 2.1 Scenario A farming family in a small village is preparing for the planting season They have been growing trees for many years, but they have not had a way to take care of and come up with harvesting methods for the trees they grow They heard that there was software on the playstore developed by the development team from GWSoft that could help them monitor their crops, plan irrigation and fertilization, and monitor yields and supply harvesting methods The family farmer decided to use garden management software provided by GWSoft They look for a software that can meet their needs, such as tracking multiple crops from which to harvest products from the crops The farmer's family was very satisfied with the software after using it It helps them monitor their crops easily They can irrigate and fertilize more effectively And they can track their productivity in more detail Most importantly, the application offers harvesting methods including: Fruit harvesting method, medicinal leaf harvesting method and wood harvesting method With the fruit harvesting method, the software will check and harvest the number of fruits on the tree based on the user's wishes When the number of fruits on the branches is not enough for the user to harvest, the software will suggest ways to help the tree grow and grow more fruits The method of harvesting tobacco leaves will be similar to the method of harvesting fruits, however the number of leaves harvested will not exceed a certain threshold because it will make it difficult for the plant to grow if harvested too much much At the same time, the software will give suggestions on how to care for the tree so that it has more leaves, to help farmers harvest later With the wood harvesting method, the software will provide methods to harvest wood with the best yield When the tree is not tall enough to harvest the correct amount of wood the user desires, the software will also provide care instructions to help the tree grow in height and have more wood Using the above software has not only helped farmers in managing the plants in their gardens, but it has also helped them harvest products from their crops more effectively 2.2 Diagram My team used the Strategy pattern to implement this scenario Below is the class diagram of the project: Figure 1: Tree Class Diagram image Class Tree: This is a basic class with attributes such as fruits, leaves, name, Weight, and HealthStatus ) In this class there are methods such as GetTreeHealth() to get health information, Fertilizing() to fertilize, UpdateTreeStatus() to update the current state of the tree, absorbCO2() to absorb CO2, and Watering() to Sprinklers Class Fruit, Wood, Medicine classes are considered products of the tree They inherit from an abstract class Product and have methods like use() to use the product Specifically: • • • Class Fruit: Has attributes such as taste) Class Wood: Has properties such as hardness, color, and makeFurniture() method to create wood furniture Class Medicine: Has attributes such as usage, medicineType, and makeProduct() method to produce medicine Interface IHarvestStrategy: This is part of the Strategy design pattern, allowing my project to define different harvesting strategies for product types There are three specific strategies: • • • FruitHarvestStrategy: Fruit harvesting strategy WoodHarvestStrategy: Wood harvesting strategy MedicineHarvestStrategy: Medicine Harvesting Strategy (Tobacco Leaves) Each strategy has a Harvest(Tree, amount) method to harvest corresponding to the type of product from the tree A tree can harvest both fruit, wood and leaves Enum HealthStatus: This is an enumeration that defines the possible health states of the plant such as Good, LackFertilize, LackWater, LackCO2, and Bad The diagram also has solid arrows from product classes to Product indicating inheritance relationships, and dashed arrows from HarvestStrategy to Product indicating that the harvest strategy uses products Implementation 3.1 Code Based on the giving class diagram above, I have created all classes that necessary for the project as shown in the image below: Figure 2: Class Library Structure image In the diagram given above, the main class that the program will interact with most is the Tree class On top of that, the class diagram also contains product abstract classes which are implemented by the Fruit class, Medicine class, Wood class Furthermore, the image also shows the harvest strategy interface, which also be implemented by the Fruit harvest strategy, Medicine harvest strategy and Wood harvest strategy The classes have been created in the image based on the attributes and names contained in the diagram class