ตรวจสอบโซลูชันเพื่อสร้างวิธีการที่นํามาใช้ใหม่ได้

เสร็จสมบูรณ์เมื่อ

โค้ดต่อไปนี้เป็นหนึ่งในวิธีแก้ไขปัญหาที่เป็นไปได้สําหรับการทดสอบจากหน่วยก่อนหน้า

Random random = new Random();
int luck = random.Next(100);

string[] text = {"You have much to", "Today is a day to", "Whatever work you do", "This is an ideal time to"};
string[] good = {"look forward to.", "try new things!", "is likely to succeed.", "accomplish your dreams!"};
string[] bad = {"fear.", "avoid major decisions.", "may have unexpected outcomes.", "re-evaluate your life."};
string[] neutral = {"appreciate.", "enjoy time with friends.", "should align with your values.", "get in tune with nature."};

TellFortune();

void TellFortune() 
{
    Console.WriteLine("A fortune teller whispers the following words:");
    string[] fortune = (luck > 75 ? good : (luck < 25 ? bad : neutral));
    for (int i = 0; i < 4; i++) 
    {
        Console.Write($"{text[i]} {fortune[i]} ");
    }
}

รหัสนี้เป็นเพียง "โซลูชันที่เป็นไปได้อย่างหนึ่ง" เนื่องจากคุณอาจเพิ่มฟีดบรรทัดในจุดต่างๆ หรือคุณอาจมีการจัดรูปแบบโค้ดที่แตกต่างกัน

โดยไม่คํานึงถึงความแตกต่างของโค้ดเพียงเล็กน้อย เมื่อคุณเรียกใช้โค้ด คุณควรเห็นหนึ่งในข้อความเอาต์พุตต่อไปนี้:

```Output A
A fortune teller whispers the following words:
You have much to look forward to. Today is a day to try new things! Whatever work you do is likely to succeed. This is an ideal time to accomplish your dreams! 
```

```Output B
A fortune teller whispers the following words:
You have much to appreciate. Today is a day to enjoy time with friends. Whatever work you do should align with your values. This is an ideal time to get in tune with nature. 
```

```Output C
A fortune teller whispers the following words:
You have much to fear. Today is a day to avoid major decisions. Whatever work you do may have unexpected outcomes. This is an ideal time to re-evaluate your life.
```

เอาต์พุตควรขึ้นอยู่กับค่าของ luck ตัวแปร

ถ้าคุณทําการทดสอบนี้เสร็จสมบูรณ์ ขอแสดงความยินดี! ดําเนินการต่อไปที่การตรวจสอบความรู้ในหน่วยถัดไป

สําคัญ

หากคุณประสบปัญหาในการดําเนินการการทดสอบนี้ให้พิจารณาตรวจสอบหน่วยก่อนหน้าก่อนที่คุณจะดําเนินการต่อ แนวคิดใหม่ ๆ ทั้งหมดที่เรากล่าวถึงในโมดูลอื่น ๆ จะขึ้นอยู่กับความเข้าใจของคุณเกี่ยวกับแนวคิดที่นําเสนอในโมดูลนี้