Partner Online Quiz
Methods
Name ________________________
1. Paste in the code below - it is from your text. Make sure it
works.
2. Create another class called party. It will have fields of day, month
time, type.
3. Create 4 more classes which will inherit from party and will be
things like picnic, etc. These will each have a slot for place
which will have an initial assignment.
4. Create a *partylist* of instances (objects) which will have
set the other slots at that time.
5. Create a set of methods for the friends. Assume each type of friend
will not be interested in each type of party. That is the hacker-
friend might only be invited to a picnic and not to a formal dance.
6. Print out invitations to each person:
Example: Dear Fran,
You are invited to a picnic
at the park on Sept. 17
See you there.
7. Print out the added code and a run (remember script?)
(defclass friend()
((name :accessor friend-name :initarg :name))
)
(defclass entrepreneur-friend (friend)())
(defclass philosopher-friend (friend)())
(defclass hacker-friend (friend)())
(defclass article()
((title :accessor article-title :initarg :title)
(author :accessor article-author :initarg :author))
)
(defclass computer-article (article) ())
(defclass business-article (article) ())
(defclass political-article (article) ())
(defclass music-article (article)())
(setf articles (list
(make-instance 'business-article :title "Down")
(make-instance 'computer-article :title "Up")
(make-instance 'political-article :title "Impugned")
(make-instance 'music-article :title "Mozart")
))
(setf friends
(list
(make-instance 'hacker-friend :name 'Dan)
(make-instance 'hacker-friend :name 'Stan)
(make-instance 'entrepreneur-friend :name 'Fran)
(make-instance 'philosopher-friend :name 'Nan)
)
)
(defun print-notification (arg1 arg2)
(format t "~% tell ~a about \"~a.\""
(friend-name arg2)
(article-title arg1))
t)
(defmethod process (( arg1 hacker-friend)
(articleclass computer-article))
(print-notification articleclass arg1))
(defmethod process ((classfriend entrepreneur-friend)
(arg2 business-article))
(print-notification arg2 classfriend))
(defmethod process ((classfriend philosopher-friend) ;;; the second parameter
(articleclass article)) ;;; is generalized to the
(print-notification articleclass classfriend)) ;;; the article class
;;; not a sub-class.
(defmethod process ((classfriend friend) ;;;a print nothing method so that
(articleclass article)) ;;;there is a default when nothing
) ;;;matches
(dolist (el friends)
(dolist (element articles)
(process el element)
)
)