diff --git a/ex-1.js b/ex-1.js index c1b94a3..bb5a517 100644 --- a/ex-1.js +++ b/ex-1.js @@ -1,3 +1,29 @@ -class EmailNotification { } +class EmailNotification { + constructor(notificationId, createdTime, content, receiver) { + this.notificationId = notificationId; + this.createdTime = createdTime; + this.content = content; + this.receiver = receiver; + } + send() { + console.log(`Notification has been sent to ${this.receiver}`); + } +} -class SMSNotification { } +class SMSNotification { + constructor(notificationId, createdTime, content, phoneNumber) { + this.notificationId = notificationId; + this.createdTime = createdTime; + this.content = content; + this.phoneNumber = phoneNumber; + } + send() { + console.log(`Notification has been sent to ${this.phoneNumber}`); + } +} + +const emailNotification = new EmailNotification(1, "2024-06-25 09:00", "Hello, this is an email notification", "example@example.com"); +const smsNotification = new SMSNotification(2, "2024-06-25 10:00", "Hello, this is an SMS notification", "1234567890"); + +emailNotification.send(); +smsNotification.send(); diff --git a/ex-2.js b/ex-2.js index 2f39244..3cee05b 100644 --- a/ex-2.js +++ b/ex-2.js @@ -1,5 +1,31 @@ -class Notification { } +class Notification { + constructor(notificationId, createdTime, content, receiver) { + this.notificationId = notificationId; + this.createdTime = createdTime; + this.content = content; + this.receiver = receiver; + } + send() { + console.log(`Notification has been sent to ${this.receiver}`); + } -class EmailNotification { } +} -class SMSNotification { } +class EmailNotification extends Notification { + constructor(notificationId, createdTime, content, receiver) { + super(notificationId, createdTime, content, receiver); + } + } + +class SMSNotification extends Notification { + constructor(notificationId, createdTime, content, receiver) { + super(notificationId, createdTime, content, receiver); + } +} + +const emailNotification = new EmailNotification(1, "2024-06-25 09:00", "Hello, this is an email notification", "example@example.com"); +const smsNotification = new SMSNotification(2, "2024-06-25 10:00", "Hello, this is an SMS notification", "1234567890"); + + +emailNotification.send(); +smsNotification.send(); \ No newline at end of file diff --git a/ex-3.js b/ex-3.js index 36756a7..30ce652 100644 --- a/ex-3.js +++ b/ex-3.js @@ -1 +1,83 @@ // Start coding here +class User { + constructor (id, name, email) { + this.id = id; + this.name = name; + this.email = email; + } +} + +class PostList { + constructor (posts) { + this.posts = posts || []; + } + addPost(post) { + this.posts.push({ + id: this.posts.length + 1, + title: post.title, + content: post.content, + comments: post.comments, + }); + } + sharePost(postTitle) { + console.log(`You've shared post ${postTitle} to your friend.`) + } +} + +class Post { + constructor (id, title, content, comment) { + this.id = id; + this.title = title; + this.content = content; + this.comment = []; + } + addComment(comment) { + this.comment.push(comment); + } +} + +class Comment { + constructor (id, content, createdBy, like) { + this.id = id; + this.content = content; + this.createdBy = createdBy; + this.like = 0; + } + addLike() { + this.like++; + } +} + +class Facebook { + constructor (groupList, pageList) { + this.groupList = []; + this.pageList = []; + } + addGroup(group) { + this.groupList.push(group); + } + addPage(page) { + this.pageList.push(page); + } +} + +class FacebookPage { + constructor (name) { + this.name = name; + } +} + +class FacebookGroup { + constructor (name) { + this.name = name; + } +} + +class notification { + constructor (id) { + this.id = id; + } + send(comment, post) { + console.log(`Notification: ${comment.createdBy.name} has just commented on this post—"${post.title}"`); + } +}