# Assignment 5 - 此次作業主題為Methods,請務必依題目提示使用作題,否則會扣分。 - The topic of this assignment is **Methods**. Please make sure to use **Methods** as instructed in the Quesiton Text. If not, points will be deducted. - 此次作業為***Console App***類型,請各位同學不要創建錯誤。 - This assignment is of the ***Console App*** type. Please make sure to create the correct project type. - 繳交方式同[Assignment 2 繳交教學](https://hackmd.io/@CCUPD2025/SJeWlJx31l),請將所有題目的`.cs` file命名完成後放在同個資料夾,最後壓縮上傳。 - The submission process follows the same steps as in Assignment 2 Submission Guide. Please name all `.cs` files correctly, place them in the same folder, and compress the folder before submission. - 務必詳閱題目,並且正確命名! - Make sure to read the instructions carefully and use the correct file names! ## Question 1 - TipCalculation Create a class named ```TipCalculation``` Include `2` overloaded methods named `CalculateTip`: - Accepts `double` **mealPrice** and `double` **tipRate** (e.g., 30.00 and 0.20) - Accepts `double` **mealPrice** and `int` **tipAmount** (e.g., 30.00 and 5) Each method should: - Display the **meal price** - Display the **tip as a percentage of the meal price** - Display the **tip in dollars** - Display the **total (meal + tip)** Include a ```Main()``` method to demonstrate both overloads ```csharp= static void Main() { TipCalculation.CalculateTip(30.00, 0.20); TipCalculation.CalculateTip(30.00, 5); } ``` #### Sample input 範例輸入: `none` #### Sample output 範例輸出: ``` Meal price: $30.00 Tip percent: 20.00% Tip amount: $6.00 Total amount: $36.00 Meal price: $30.00 Tip percent: 16.67% Tip amount: $5.00 Total amount: $35.00 ``` ## Question 2 - InputMethodDemo2 Create a program named ```InputMethodDemo2``` Simplify the ```InputMethod()``` from ```InputMethodDemo``` (original had repetitive code) Rewrite ```InputMethod()``` to contain only `4` statements (Including `2` `Write()` line) ***!!! Maintain the same behavior as the original but with reduced code repetition !!!*** ![image](https://hackmd.io/_uploads/Bk6AKvLxll.png) #### Sample input 範例輸入: Enter first integer `10` Enter second integer `20` #### Sample output 範例輸出: ``` After InputMethod first is 10 and second is 20 ``` ## Question 3 - Averages Create a program named `Averages` Include a method(you can choose any name) that: - Accepts any number of numeric parameters (e.g., using params) ```csharp= public static void ShowAverage(params double[] numbers) { // ... } ``` - Displays the input numbers - Calculates and displays **their average** Demonstrate the method by passing: - `1` number - `2` numbers - `3` numbers - An array of numbers ```csharp= ShowAverage(10); ShowAverage(15.5, 24.5); ShowAverage(5, 10, 15); double[] values = { 20, 40, 60, 80 }; ShowAverage(values); ``` #### Sample input 範例輸入: `none` #### Sample output 範例輸出: ``` Numbers: 10 Average: 10.00 Numbers: 15.5, 24.5 Average: 20.00 Numbers: 5, 10, 15 Average: 10.00 Numbers: 20, 40, 60, 80 Average: 50.00 ``` ## Question 4 - SortWords Create a program named `SortWords` Include a method(you can choose any name) that: - Accepts any number of words (e.g., using params string[]) - Sorts the words in alphabetical order - Displays the sorted list Demonstrate the method by passing: - `1` word - `2` words - `5` words - `10` words ```csharp= SortWord("banana"); SortWord("zebra", "apple"); SortWord("cherry", "apple", "banana", "fig", "date"); SortWord("peach", "grape", "kiwi", "mango", "apple", "banana", "fig", "date", "plum", "cherry"); ``` #### Sample input 範例輸入: `none` #### Sample output 範例輸出: ``` banana apple zebra apple banana cherry date fig apple banana cherry date fig grape kiwi mango peach plum ``` ## Question 5 - Movie Create a program named `Movie` Include a method(you can choose any name) that: - Accepts a **movie name (string)** and **duration (int, `minutes`)** - Sets the default value of **duration** to `90` if not provided - Displays the **movie name** and **duration** In `Main()`, demonstrate: - Calling the method with just the **movie name** - Calling the method with **movie name** & **duration** ```csharp= DisplayMovieInfo("Spirited Away"); DisplayMovieInfo("Inception", 148); ``` #### Sample input 範例輸入: `none` #### Sample output 範例輸出: ``` Movie name: Spirited Away Duration: 90 minutes Movie name: Inception Duration: 148 minutes ```