--- title: 'Seminar #1 - Mermaid' disqus: hackmd --- Seminar #1 - Mermaid - 17/32 === * 1712795 - Phan Tấn Thịnh * 1712827 - Trần Quốc Toản ## Flow Chart ### Euclide GCD > Ước chung lớn nhất của 2 số tự nhiên A, B ```mermaid graph TD start([START]) --> step1[INPUT A, B] step1 --> tinyCircle(( )) tinyCircle --> step2{B = 0} step2 -- No --> step3{A > B} step3 -- No --> step4[B = B - A] step3 -- YES --> step5[A = A - B] step2 -- YES --> step6[PRINT A] step4 --> goto2[BACK TO STEP 2] step5 --> goto2 step6 --> finish([END]) goto2 --> tinyCircle classDef yellow fill:#fbc71c,stroke-width:2px,stroke:#000,font-size:11px,font-weight:bold classDef cyan fill:#8acee7,stroke-width:2px,stroke:#000,font-size:11px,font-weight:bold classDef green fill:#81d981,stroke-width:2px,stroke:#000,font-size:11px,font-weight:bold class step1,tinyCircle,step4,step5,step6,goto2 cyan class step2,step3 yellow class start,finish green ``` ### Quadratic Equation > ax<sup>2</sup> + bx + c = 0 ```mermaid graph TD start(Bắt đầu) --> step1[INPUT a, b, c] step1 --> step2{a = 0} step2 -- Đúng --> step3{b = 0} step3 -- Đúng --> step4{c = 0} step4 -- Đúng --> resultR[Vô số nghiệm] step4 -- Sai --> result01[Vô nghiệm] step3 -- Sai --> result11[Một nghiệm<br>x = -c/b <br>] step2 -- Sai --> step5["#8710; = b^2 - 4ac"] step5 --> step6{"#8710;>= 0"} step6 -- Sai --> result02[Vô nghiệm] step6 -- Đúng --> step7{"#8710; = 0"} step7 -- Đúng --> result12[Một nghiệm<br>x = -b/2a] step7 -- Sai --> result2["Hai nghiệm<br>x1 = (-b - #8730;#8710;)/2a<br>x2 = (-b + #8730;#8710;)/2a"] resultR --> finish(Kết thúc) result01 --> finish result02 --> finish result11 --> finish result12 --> finish result2 --> finish classDef yellow fill:#fbc71c,stroke-width:2px,stroke:#000,font-size:12px,font-weight:bold classDef cyan fill:#8acee7,stroke-width:2px,stroke:#000,font-size:12px,font-weight:bold classDef green fill:#81d981,stroke-width:2px,stroke:#000,font-size:12px,font-weight:bold class step1,step5,resultR,result01,result02,result11,result12,result2 cyan class step2,step3,step4,step6,step7 yellow class start,finish green ``` ## Class Diagram ```mermaid classDiagram Address "1" --* "1" Customer : Has Customer "1" -- "*" Product : Purchases Product "*" -- "1" Customer : Is Sold To Customer -- PurchaseDetail Product -- PurchaseDetail PremiumCustomer --|> Customer RegularCustomer --|> Customer Bill --o Customer : Belongs To Bill ..> PurchaseDetail Bill ..> Discount Discount ..> PurchaseDetail Bill ..|> PaymentCounter : Accepts class Address{ street: String city: String state: String zipcode: Int enterStreet() enterCity() enterState() enterZipcode() } class Product{ productID: Int productName: String productPrice: Float getPrice() setPrice() } class Customer{ custName: String custID: Int custPhnum: Int purchaseItem() requestBill() enterCustDetail() } class PremiumCustomer{ premiumDiscount: Int enterCustDetail() } class RegularCustomer{ regularDiscount: Int enterCustDetail() } class PurchaseDetail{ custID: Int quantity: Int purchaseDate: Date productID: Int calculateTotalAmt() generatePurchaseList() } class Discount{ discountType discountValue SelectDiscount() } class Bill{ payableAmt calculatePayableAmt() generateBill() } class PaymentCounter { << interface >> calculatePayableAmt() generateBill() } ``` ## Sequence Diagram **Search Book : Use Case** - **Main scenario** 1. The Customer specifies an author on the Search Page and then presses the Search button. 1. The system validates the Customer's search criteria. 1. If author is entered, the System searches the Catalog for books associated with the specified author. 1. When the search is complete, the system displays the search results on the Search Results page. - **Altenate path** If the Customer did not enter the name of an author before pressing the Search button, the System displays an error message ```mermaid sequenceDiagram activate Customer Customer ->> SearchPage : 1: onSearch(author) activate SearchPage SearchPage ->> SearchPage : 1.1: validateSearchCriteria() alt author entered SearchPage ->> Catalog : 1.2: searchByAuthor(author) activate Catalog Catalog ->> SearchResults : 1.2.1: create() activate SearchResults SearchResults ->> SearchResultPage : 1.2.1.1: display() activate SearchResultPage deactivate SearchResultPage deactivate SearchResults deactivate Catalog else author not entered SearchPage ->> SearchPage : 1.3: displayErrorMessage() end deactivate SearchPage deactivate Customer ``` ## State Chart Diagram > ATM Machine State Diagram ```mermaid stateDiagram [*] --> Idle Idle --> VerifyAccount state VerifyAccount { state VerifyCard { cardSubmitted readCard returnCard } VerifyCard --> CheckIfCardValid CheckIfCardValid --> Idle : else CheckIfCardValid --> CardValid : cardValid CardValid --> VerifyPin state VerifyPin { pinSubmitted checkPin returnCard } VerifyPin --> CheckIfPinCorrect CheckIfPinCorrect --> PinCorrect : PINValid CheckIfPinCorrect --> PinIncorrect : else PinIncorrect --> VerifyPin : [tries < maxTries]/tries ++ } TransactionComplete --> Idle PrintReceipt --> TransactionComplete DispenseMoney --> PrintReceipt DispenseMoney --> TransactionComplete AccountAction --> DispenseMoney AccountAction --> PrintReceipt ``` > [Github Repo](https://github.com/yato511/Markdown) ###### tags: `TKPM-Mermaid`