Notification System
Submit solution
Points:
50
Time limit:
1.0s
Memory limit:
10M
Author:
Problem type
Allowed languages
Java 19
Description
某系統會發送不同類型通知:
EmailNotification 為 Email 通知,SMSNotification 為簡訊通知、AppNotification 為 App 推播通知。
請使用多型 (Polymorphism) 管理所有通知。
Requirements
第一行輸入通知數量 n,接著輸入 n 筆通知資料:
| 類型 | 格式 |
|---|---|
| EmailNotification | EmailNotification user |
| SMSNotification | SMSNotification user |
| AppNotification | AppNotification user |
需使用物件:Notification[] notifications
且每個子類別需 Override:send()並依序輸出通知結果。
Output
| 類型 | 輸出格式 |
|---|---|
| EmailNotification | Send EMAIL to user |
| SMSNotification | Send SMS to user |
| AppNotification | Send APP to user |
Hint
class Notification {
protected String user;
public Notification(String user) {
this.user = user;
}
public void send() {
System.out.println(user);
}
}
子類別可透過 Override 改寫:
@Override
public void send() {
System.out.println("Send EMAIL to " + user);
}
Sample Input 1
3
EmailNotification Alice
SMSNotification Bob
AppNotification Kevin
Sample Output 1
Send EMAIL to Alice
Send SMS to Bob
Send APP to Kevin
Sample Input 2
5
SMSNotification Tom
SMSNotification Amy
EmailNotification John
AppNotification Mary
EmailNotification David
Sample Output 2
Send SMS to Tom
Send SMS to Amy
Send EMAIL to John
Send APP to Mary
Send EMAIL to David
Comments