---
# System prepended metadata

title: 'BÀI TẬP SEMINAR #1 - Mermaid'
tags: [TKPM-Mernaid]

---

# BÀI TẬP SEMINAR #1 - Mermaid

###### tags: `TKPM-Mernaid`


## :star: Danh sách nhóm

### :one: 1712083 - Danh Phi Long
### :two: 1712086 - Nguyễn Tân Gia Lợi
### :three: 1712121 - Nguyễn Tấn Phát

## :star: Bài tập

### Flow chart

- ### Euclide GCD
 -- Mermaid code：
 ```
graph TD
    .((start)) --> A(input a, b)
    A --> |loop| B[c = a mod b]
    B --> C{c = 0 ?}
    C -->|yes| D(print b)
    D --> ..((stop))
    C -->|no|E[a = b, b = c]
    E --> C	
```
-- Diagram
```mermaid
graph TD
	.((start)) --> A(input a, b)
	A --> |loop| B[c = a mod b]
	B --> C{c = 0 ?}
	C -->|yes| D(print b)
	D --> ..((stop))
	C -->|no|E[a = b, b = c]
	E --> C	
```
- ### Quadratic Equation
-- Mermaid code：
```
graph TD
    .((start)) --> A(input a, b, c)
    A --> B[del = b^2 - 4ac]
    B --> C{del >= 0 ?}
    C --> |yes| D["x1 = (-b + sqrt(del))/(2a)"]
    D --> F["x2 = (-b - sqrt(del))/(2a)"]
    F --> H(print x1, x2)
    H --> M((stop))
    C --> |no| E(print 'No real solution')
    E --> M
```
-- Diagram
```mermaid
graph TD
    .((start)) --> A(input a, b, c)
    A --> B[del = b^2 - 4ac]
    B --> C{del >= 0 ?}
    C --> |yes| D["x1 = (-b + sqrt(del))/(2a)"]
    D --> F["x2 = (-b - sqrt(del))/(2a)"]
    F --> H(print x1, x2)
    H --> M((stop))
    C --> |no| E(print 'No real solution')
    E --> M
```
### Class Diagram
- Mermaid code:
```
classDiagram
    Customer "1"*--"1" Address
    %%Customer "Has"*-- Address
    Customer "1"--"*" Product
    %%Customer "Is Sold To"--"Purchases" Product
    Customer -- PurchaseDetail
    Customer <|-- PremiumCustomer
    Customer <|-- RegularCustomer
    Customer o--"Belongs to" Bill
    PurchaseDetail <.. Discount
    PurchaseDetail -- Product
    PurchaseDetail <.. Bill
    Discount <.. Bill
    PaymentCounter <.. Bill :Accepts
    
    
    class Address
    Address : street: String
    Address : city: String
    Address : state: String
    Address : zipcode: String
    Address : enterStreet()
    Address : enterCity()
    Address : enterState()
    Address : enterZipcode()
    
    class Customer{
        custName: String
        custID: String
        custPhnum: Int
        + purchaseItem()
        + requestBill()
        + enterCustDetail()
    }
    
    class Product{
        productId: Int
        productName: String
        productPrice: Float
        + getPrice()
        + setPrice()
    }
    
    class PurchaseDetail{
        custID: Int
        quantity: Int
        purchaseDate: Date
        productID: Int
        + calculateTotalAmt()
        + generatePurchaseList()
    }
    
    class Discount{
        discountType
        discountValue
        + SelectDiscount()
    }
    
    class Bill{
        payableAmt
        + calculatePayableAmt()
        + generateBill()
    }
    
    class RegularCustomer{
        regularDiscount: Int
        + enterCustDetail()
    }
    
    class PremiumCustomer{
        premiumDiscount: Int
        + enterCustDetail()
    }
    
    class PaymentCounter{
        <<interface>>
        + calculatePayableAmt()
        + generateBill()
    }
```

- Diagram
```mermaid
classDiagram
    Customer "1"*--"1" Address
    %%Customer "Has"*-- Address
    Customer "1"--"*" Product
    %%Customer "Is Sold To"--"Purchases" Product
    Customer -- PurchaseDetail
    Customer <|-- PremiumCustomer
    Customer <|-- RegularCustomer
    Customer o--"Belongs to" Bill
    PurchaseDetail <.. Discount
    PurchaseDetail -- Product
    PurchaseDetail <.. Bill
    Discount <.. Bill
    PaymentCounter <.. Bill :Accepts
    
    
    class Address
    Address : street: String
    Address : city: String
    Address : state: String
    Address : zipcode: String
    Address : enterStreet()
    Address : enterCity()
    Address : enterState()
    Address : enterZipcode()
    
    class Customer{
        custName: String
        custID: String
        custPhnum: Int
        + purchaseItem()
        + requestBill()
        + enterCustDetail()
    }
    
    class Product{
        productId: Int
        productName: String
        productPrice: Float
        + getPrice()
        + setPrice()
    }
    
    class PurchaseDetail{
        custID: Int
        quantity: Int
        purchaseDate: Date
        productID: Int
        + calculateTotalAmt()
        + generatePurchaseList()
    }
    
    class Discount{
        discountType
        discountValue
        + SelectDiscount()
    }
    
    class Bill{
        payableAmt
        + calculatePayableAmt()
        + generateBill()
    }
    
    class RegularCustomer{
        regularDiscount: Int
        + enterCustDetail()
    }
    
    class PremiumCustomer{
        premiumDiscount: Int
        + enterCustDetail()
    }
    
    class PaymentCounter{
        + calculatePayableAmt()
        + generateBill()
    }
```
- Class Diagram (rendered by live editor): 
![](https://i.imgur.com/u6uuy8L.png)

### Sequence Diagram
- Mermaid code：
```
sequenceDiagram
    participant Cu as Customer
    participant SP as Search Page
    participant SRP as Search Result Page
    participant C as Catalog
    participant SR as Search Results
    activate Cu
    Cu->> SP: 1:OnSearch(author)
    activate SP
    SP->>SP: 1.1:validateSearchCriteria()
    alt author entered
        SP ->>+ C: 1.2: searchByAuthor(author)
        activate C
        C ->> SR: 1.2.1: create()
        activate SR
        SR ->> SRP: 1.2.1.1: display()
        activate SRP
        deactivate SRP
        deactivate SR
    else author not entered
        deactivate C
        SP ->> SP: 1.3: displayErrorMessage()
        deactivate SP
    end
    deactivate Cu
```
- Diagram：
```mermaid
sequenceDiagram
    participant Cu as Customer
    participant SP as Search Page
    participant SRP as Search Result Page
    participant C as Catalog
    participant SR as Search Results
    activate Cu
    Cu->> SP: 1:OnSearch(author)
    activate SP
    SP->>SP: 1.1:validateSearchCriteria()
    alt author entered
        SP ->>+ C: 1.2: searchByAuthor(author)
        activate C
        C ->> SR: 1.2.1: create()
        activate SR
        SR ->> SRP: 1.2.1.1: display()
        activate SRP
        deactivate SRP
        deactivate SR
    else author not entered
        deactivate C
        SP ->> SP: 1.3: displayErrorMessage()
        deactivate SP
    end
    deactivate Cu
```

### State Chart Diagram
 - Mermaid code：
 ```
stateDiagram
	[*] --> AD
	AD: IDLE
	D: PrintReceipt
	C: DispenseMoney
	B: AcountActions
	AD--> VerifyAcount	
	B --> C
	C --> D
	B --> D	
	C --> [*]
	D --> [*]
	state VerifyAcount{
		A: VerifyCards
		B: CardValid
		C: VerifyPin
		D: PinCorrect
		G:valid
		F: PinCorrect
		B-->C
		C-->F
		F-->D:PINValid
		F-->E :else
		E-->C: [tries<maxTries] tries++
		A-->G
		G-->B: cardValid
	}
```
- Diagram
```mermaid
stateDiagram
	[*] --> AD
	AD: IDLE
	D: PrintReceipt
	C: DispenseMoney
	B: AcountActions
	AD--> VerifyAcount	
	B --> C
	C --> D
	B --> D	
	C --> [*]
	D --> [*]
	state VerifyAcount{
		A: VerifyCards
		B: CardValid
		C: VerifyPin
		D: PinCorrect
		G:valid
		F: PinCorrect
		B-->C
		C-->F
		F-->D:PINValid
		F-->E :else
		E-->C: [tries<maxTries] tries++
		A-->G
		G-->B: cardValid
	}
```
- State Chart Diagram (rendered by live editor): 
![](https://i.imgur.com/Jf40Jiw.png)
