---
# System prepended metadata

title: Assignment 6

---

# Assignment 6
- 此次作業主題為Class & Object，請務必依題目提示使用作題，否則會扣分。
    - The topic of this assignment is **Class & Object**. Please make sure to use **Class & Object** 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 - ShirtDemo
Create an program(also a class) named `ShirtDemo` and put your `Main()` inside it.

Create a `Shirt` class with **auto-implemented** properties:
- Material 
- Color
- Size

***`Auto-implemented`*** code(inside `Shirt` class):
```csharp=
public string Material { get; set; }
public string Color { get; set; }
public string Size { get; set; }
```


In `ShirtDemo` class:
- Declare multiple shirts
    ```csharp=
    Shirt s1 = new Shirt { Material = "Cotton", Color = "Blue", Size = "M" };
    Shirt s2 = new Shirt { Material = "Linen", Color = "White", Size = "L" };
    Shirt s3 = new Shirt { Material = "Polyester", Color = "Black", Size = "S" };
    ```
- Write a method(any name) that **takes several `Shirt` objects** & **displays their information**.
    ```csharp=
    DisplayShirt(s1, s2, s3);
    ```
    > Remember to use `params`
    > and you can override `ToString()` to make it easier.
#### Sample input 範例輸入:
`none`
#### Sample output 範例輸出:
```
Material: Cotton, Color: Blue, Size: M  
Material: Linen, Color: White, Size: L
Material: Polyester, Color: Black, Size: S
```
## Question 2 - ConferencesDemo
Create a program(also a class) named `ConferencesDemo`

Create a `Conference` class with:
- GroupName (`string`)
- StartDate (`string`)
- Attendees (`int`)

Implement `IComparable.CompareTo()` to sort by **`Attendees`**
(from smallest to largest)

In a `ConferencesDemo` class, accept and sort `5` conferences using the code below:
```csharp=
static void Main()
{
    Conference[] conferences = new Conference[]
    {
        new Conference("Tech Summit", "2025-06-10", 250),
        new Conference("AI Conference", "2025-07-05", 400),
        new Conference("Health Forum", "2025-05-20", 180),
        new Conference("Green Energy Expo", "2025-08-15", 300),
        new Conference("Finance Symposium", "2025-09-01", 220)
    };

    Array.Sort(conferences);

    Console.WriteLine("Conferences sorted by number of attendees:");
    Console.WriteLine();
    foreach (Conference conf in conferences)
    {
        Console.WriteLine(conf);
    }
}
```
#### Sample input 範例輸入:
`none`
#### Sample output 範例輸出:
```
Conferences sorted by number of attendees:

Health Forum - 2025-05-20 - 180 attendees
Finance Symposium - 2025-09-01 - 220 attendees
Tech Summit - 2025-06-10 - 250 attendees
Green Energy Expo - 2025-08-15 - 300 attendees
AI Conference - 2025-07-05 - 400 attendees
```
## Question 3 - RelativesBirthday
Create a program named `RelativesBirthday` 

Create a `Relative` class with ***`auto-implemented`*** properties:
- Name
- Relationship (`string`)
- Birthday
    -  Month (`int`)
    -  Day (`int`)
    -  Year (`int`)

Create the relative list using the code below:
```csharp=
Relative[] relativeList = new Relative[]
{
    new Relative { Name = "Alice", Relationship = "Friend", Month = 1, Day = 15, Year = 1995 },
    new Relative { Name = "Bob", Relationship = "Brother", Month = 2, Day = 20, Year = 1990 },
    new Relative { Name = "Cathy", Relationship = "Colleague", Month = 3, Day = 10, Year = 1988 },
    new Relative { Name = "David", Relationship = "Father", Month = 4, Day = 5, Year = 1960 },
    new Relative { Name = "Ella", Relationship = "Sister", Month = 5, Day = 25, Year = 1993 },
    new Relative { Name = "Frank", Relationship = "Uncle", Month = 6, Day = 30, Year = 1970 },
    new Relative { Name = "Grace", Relationship = "Aunt", Month = 7, Day = 12, Year = 1975 },
    new Relative { Name = "Henry", Relationship = "Grandpa", Month = 8, Day = 3, Year = 1945 },
    new Relative { Name = "Isabel", Relationship = "Grandma", Month = 9, Day = 8, Year = 1948 },
    new Relative { Name = "Jack", Relationship = "Friend", Month = 10, Day = 21, Year = 1996 },
    new Relative { Name = "Karen", Relationship = "Mom", Month = 11, Day = 18, Year = 1965 },
    new Relative { Name = "Leo", Relationship = "Dad", Month = 12, Day = 2, Year = 1962 }
};
```

- - -

Allow the user to **repeatedly** search for a relative by `name`.

Display `birthday` and `relationship` or a “Not found” message if a relative name does not exist.

Override `ToString()` code:
```csharp=
public override string ToString()
{
    return $"{Name} - {Relationship}, Birthday: {Month}/{Day}/{Year}";
}
```

> You can use any method you like to find the specific relative. (loop or library method etc)

#### Sample input 範例輸入:
```
Frank
Alice
Kavic
```
#### Sample output 範例輸出:
```
Frank - Uncle, Birthday: 6/30/1970
Alice - Friend, Birthday: 1/15/1995
Not found
```
## Question 4 - DemoJobs
Write a demo program called `DemoJobs`

Create a `Job` class that represents a home service task. 


| Field Name  | Type     | Description                                   |
| ----------- | -------- | --------------------------------------------- |
| Description | `string` | Description of the job (e.g., "wash windows") |
| Hours       | `double` | Time to complete the job in hours (e.g., 3.5) |
| Rate        | `double` | Hourly rate charged (e.g., $25.00)            |
| TotalFee | `double` | Total fee, calculated as `Hours × Rate` (**read-only property**) |

- `Description`, `Hours`, and `Rate`: Should have standard ***get*** and ***set*** accessors. **(auto-implemented)**

- `TotalFee`: Should be a **read-only property** that automatically calculates the value whenever accessed. 

`TotalFee` code:
```csharp=
 public double TotalFee
 {
     get
     {
         return ...;
     }
     // no setter
 }
```

---
Implement the required fields and methods, and overload the `+` operator to allow combining two jobs. 

### Rules for Combining Jobs:

- `Description`: Concatenate the two job descriptions with **" and "** (e.g., "Wash windows **and** Clean garage")
- `Hours`: **Sum** of both jobs’ hours
- `Rate`: **Average** of the two hourly rates
    ```csharp
    (job1.Rate + job2.Rate) / 2;
    ```
- `TotalFee`: Automatically recalculated using the new hours and rate
- - -
Override `ToString()`:
```csharp=
public override string ToString()
{
    return $"Job: {Description}\n" +
           $"Hours: {Hours}\n" +
           $"Rate: ${Rate:F2} per hour\n" +
           $"Total Fee: ${TotalFee:F2}\n";
}
```
Then, demonstrate the functionality of the class `Job` in `DemoJobs`.

```csharp=
static void Main()
{
    Job job1 = new Job("Wash windows", 3.5, 25.00);
    Job job2 = new Job("Clean garage", 2.0, 30.00);
    Console.WriteLine("Job 1:");
    Console.WriteLine(job1);
    Console.WriteLine("Job 2:");
    Console.WriteLine(job2);
    Job combinedJob = job1 + job2;
    Console.WriteLine("Combined Job:");
    Console.WriteLine(combinedJob);
}
```

#### Sample input 範例輸入:
`none`
#### Sample output 範例輸出:
```
Job 1:
Job: Wash windows
Hours: 3.5
Rate: $25.00 per hour
Total Fee: $87.50

Job 2:
Job: Clean garage
Hours: 2
Rate: $30.00 per hour
Total Fee: $60.00

Combined Job:
Job: Wash windows and Clean garage
Hours: 5.5
Rate: $27.50 per hour
Total Fee: $151.25
```