CS 122 Winter
2001, Instructor: Jeffrey Horn
General
Student Concerns: Colloquia
and Seminars Local
Events NMU
CS Employment
SCHEDULE FOR NEXT TWO WEEKS (or so):
Mon.
4/16
|
Tues.
4/17
|
Wed.
4/18
|
Thurs.
4/19
|
Friday
4/20
|
Monday
4/23
|
Tuesday
4/24
|
Wed.
4/25
|
Thur.
4/26
|
Fri.
4/27
|
Lecture
|
Lab
|
Lecture
|
Lecture
|
Last Day!
(donuts)
|
ROBOTS! |
Me Gone
|
Study Session/Lab
at 5:00pm
|
FINAL
EXAM
8:00 am
NSF 1205
|
|
Take-Home Exam 3 handed
out
|
"Final Exam"
Program
handed out
|
Take-Home Exam 3 due
|
HW 5 due
(solutions)
|
|
check
web
|
check
web
|
Room TBA,
but most likely NSF 1205
(our usual!)
HW6 due
(solutions)
|
"Final Exam" Program
due
|
|
-
What's REALLY New:
-
Added drop box for final project
(a.k.a., "HW 7"). See WebCT.
-
Solution for HW6 (see link below)
will work starting at the review session Wed., 5pm.
-
REVIEW SESSION: We
are still on for Wed. at 5pm, and I am pretty sure we have 1205 all to
ourselves. If not, we'll move somewhere close by, and I will put
a sign on the door of 1205 so you'll know where to go.
-
HW4 (sorting) solution is now on
the web! and on the Instructor's Server! See link below, under
HW4.
-
Not so New (Older Announcements):
-
Moved due date of HW6 since I will
be out on Tuesday. The real deadline for HW 6 is when the solutions
are handed out!
-
Added Solutions to HW 2, 3, and
5, to web (see homeworks below for links) and to Instructors server.
-
Finalized FINAL PROJECT details.
And anyone can take this option.
-
Changed the due date of HW 6.
-
Added Take-Home Exam 3. See
below.
-
Updated "good" and "bad" prisoners
on both web and Instructors server. Also updated Tournaments code
to conduct all of the tournaments in Exam 2.
-
Updated some of the prisonerA class
files on the web, and put FOUR baddies in "bad_Prisoner". Use the
link to the prisoners below in the HW5 assignment on this page. Sorry,
I could not update the appropriate folders on the Instructor server.
I could not logon to the server as of this afternoon. Will try again
Monday. But you can get 14 working prisoners from the web right now.
This is for HW5.
-
I will try to run the full QUIZ
2 tournaments on Monday. See you then!
-
Also, For those of you who missed
a lecture or two, I have graded Quiz 1. Your grades are on Web CT
and I have graded hardcopy to give back to you (Jason, Steph, Chris, for
example). If you do not see a grade there, and you are sure you turned
it in, let me know! (email jhorn@nmu.edu is fine)
-
Added the Tournaments controller
code to hold tournaments among prisoners in an array. This is the
code from lecture. See below in HW 5 for link to code. Also
on instruct server.
-
The assignment drop box for the
Prisoners' Dilemma exam is now working! Please turn in that
.class file!
-
Also note that the file "prisoner.java",
containing the interface "prisonerA", MUST have the same filename as interface
name (just as for any java Class definition), so please change the file
name to "prisonerA" to agree with the interface name. I have already
done this on the on-line file (link below).
-
Take-Home Exam 2 (Prisoners'
Dilemma and Interfaces) Handed Out, due Friday, 3/30/01. See below.
-
-
Instead, just do this
take-home exam and turn it in when i get back!
-
NOTE: For HW4, DO NOT recompile
the file "SortCanvas.java", as this is a slightly newer, slightly incompatible
version of the code from what is in "SortCanvas.class". If you have
already recompiled it, then go back to the instruct server or the web and
get the original SortCanvas.class file. Sorry, will straighten this
out when I get back!
-
KEEP AN EYE ON THIS WEB PAGE!
whilst I am gone at EMO
-
HW 4 (see below)
-
(FIXED LINK! 2/22) HW 1 SOLUTION
is out. See link below under HW 1 assignment. It is also on the INSTRUCT
SERVER.
-
EXTRA CREDIT for this Friday's colloquiua.
We have a guest speaker, Dr. John Yen from Texas A&M, giving two talks,
one at 10 am in NSF 1207 and one at 2pm in Jamrich 218. Click here
for
more info, including titles and abstracts of the two talks.
-
If you go AND send me an email with
a paragraph or so that shows some thought (see below) then I will award
up to 10 pts extra (out of 100) on a homework assignment.
-
By "showing thought" I mean something
more than "I went there. He talked. he was OK." (Believe
me, I get this kind of thing all the time!) You can summarize the
main points, but even better, just take off on a tangent, or pick up on
one aspect you did understand and tell me what you think. Do you
have any ideas? Did anything inspire you? Keep it short.
This is just to show you were alive and thinking.
-
HW3 will be assigned on the web
Friday, Feb. 9, unless we are snowed out!
-
Updated LIFE code after Thurs..
lecture. The code for John Conway's LIFE, developed in class this week,
is on the web at http://cs.nmu.edu/~jeffhorn/Classes/CS122/Winter2001/Code/Life
and also on the Instructor server
-
HW 2 is now due Wed., Feb. 7, anytime.
I have now added the ASIGNMENT DROPBOX on WebCT, which closes midnight
end of Wed. Feb. 7. Just hand in what you have by then, no matter
what works and what doesn't, for partial credit and for feedback!
-
HW 2 is now due Sat. Feb. 3, so
that we can use lab day on Friday, Feb. 2 towards getting it done.
I have further clarified the instructions below, but keep checking the
actual code for additional explanations and examples, since I can update
this from off campus. Look in the comments. I will be updating
the code linked to in HW 2 below (at http://cs.nmu.edu/~jeffhorn/Classes/CS122/Winter2001/HW2/Code/creature)
which I will also stick in the LatestCreatureCode folder, but I'm afraid
I can't update the Instruct. folder from off-campus, so that won't be updated
with the latest code until Tuesday morning.
-
REMINDER: No class on Monday
Jan 29. Instead, an optional lab will be held in our classroom on
TUESDAY, Jan. 30. at 9:00 am. (you are welcome to use our classroom
on Monday at 9am! But I won't be there.) And NO OFFICE hours
that Monday either. Consider it moved to Tuesday (same time) also!
-
ALSO, the following Tuesday, Feb.
6, we will have another optional lab (at 9am) in lieu of lab on that Friday,
Feb. 9. I will still have my normal Friday office hours however (since
I WILL be around that day).
-
So basically, we have two more lab
days, Tuesday and Friday, Jan. 30 and Feb. 2) for HW2, with lectures on
the wed. and thurs inbetween.
-
HW 2 will be assigned Wed. this
week (Jan 24), but I have already started the description below, for those
who can start early on it. No, the code is not online yet, so wait
'til Wed.!
-
From now on, I will try to make
the LATEST "CreatureWorld" code, that we have been writing in lectures,
on the web (click here,
and also below, under HOMEWORKS AND PROGRAMS) and also on our Instructors
Server folder in "Latest Creatures World". I will try to update this
everyday after class, but you don't have to use this code! I expect
you to copy and paste the pieces and ideas you need (or just want).
I am open to suggestions, outside of class too, to improve our simulation!
-
Hand in HW1 today! (Monday,
Jan. 22) for FULL credit. Otherwise, 5% by Tuesday, and another 5%
off if by Wed., but NOTE THAT I WILL HAND OUT SOLUTIONS WEDNESDAY AT 9am,
so no HW1 assignments accepted after that!
-
I was able to log into the INTRUCTOR's
SERVER today, finally! You can now find HW1, and also HiWorld,
in the Math_CS/jhorn/CS_122/Winter2001 folder.
-
I have further updated the code
in HW1 with what we did today (Jan. 15) in class (got creatures bouncing
off the walls correctly, random initial directions, etc.) But
the most important change, which I would like you to have in your code,
is that a creature's HEALTH value now changes! (with movement and
with contact with the "walls".) Without changing health, the stats
(avg., max., and min.) would be pretty boring!
-
I have sped up the animation and
added some code to change the creature's health.
-
Also, if you want the code for "hi
world" it is
here
-
Added Homework 1, due Friday, Jan.
19, see below.
-
Professor Ellerbruch has some excellent
Java links. Check out his page:
CONTENTS
LECTURE NOTES
The JAVA model of Computation (Translation and Execution)
FILE INPUT/OUTPUT in Java
HOMEWORKS & PROGRAMS
Latest
Creature World code
Homework 1 "Review of Arrays, Intro to Applications"
-
Handed out Friday, Jan 12, 2001,
-
Due: Friday, Jan. 19, 2001.
-
Based on the code we developed in class, Creature World:
-
Make YOUR OWN creature class! Be creative on
its appearance! (i.e., "paint" method)
-
Make an array of creatures
-
Initialize 8 different creatures in the array
-
Make sure each creature moves with each time step
-
Compute the follwing statistics each time step, printing
them at the bottom of the window:
-
Number of creatures
-
Average health
-
Min health
-
Max health
-
You can download the code from the web (click here)
or from the Instructor's server
-
Hand-in instructions: Go to WebCT and turn ALL of your
".java" files (the source code). I don't need your stinkin' ".class"
files, 'cause I can generate them myself!
-
SOLUTION
(also on Instruct Server)
Homework 2 "More Arrays, Better Simulation!"
-
Handed out Wednesday, Jan 24, 2001,
-
Due: Saturday, Feb. 3, 2001.
-
Look in the .java files (at link below) for comments and
examples of how to do these things.
-
Based on the latest code (CLICK HERE)
we developed in class, Creature World, and your own version:
-
Add code to find and delete the n_kill least healthy
creature from the population each time step (up to 10 pts.)
See comments in Population.java
for suggestions here.
-
Add code to find and reproduce the n_birth healthiest
creatures in the population (i.e., copy and add them to the pop) EACH TIME
STEP (<= 10 pts). See comments in Population.java
for suggestions here.
-
Add code to calculate the number of creatures within a radius
r
of a creature, and then give the creature food (health) based on that neighborhood
number as follows: (<= 10 pts)
-
Suggest you do this in pieces.
-
One method in creature can return the distance between
the creature at x,y and given (input) x_input , y_input coordinate
(just use Pythagorem's theorem: d2 = (x - x_input)2
+
(y-y_input)2 and return d.
-
then maybe a method in Population can, for a given
(input) creature c, go through the array of creatures and call the
above method, as in c.distance(creatures[i]), compare the distance
returned to the given radius r. If d<r, then increment
the counter. Once that loop is done, the counter has the number of
creatures within distance r. Return that.
-
Then have another method in Population, use that value
(number of creatures in neighborhood) to reduce the health of that creature,
and hence its ability to reproduce. For example, if you increment
health of each creature by 10 every time step, then instead increment it
by 10/N, where N is the just-calculated number of creatures
nearby.
-
Add buttons to do SOMETHING (e.g., start and stop the simulation,
or add or delete creatures, or...) (<= 10 pts)
-
Suggest you use the Button class from CS 120. Just
get a copy of AButton.class
and stick into your creatures folder. You might want to look at the
source code, AButton.java,
so refresh your memory on how to use it. (It is in the book too!
Also on the Instructors server in our HW2 folder).
-
Implement MouseListener interface, as in the HW2 code.
This means
-
saying that your main class implements MouseListener
and
-
defining ALL of the methods in the MouseListener interface
(see the HW2 World.java code), most of them with empty statement bodies,
and
-
calling the addMouseListener() method from somewhere
within your World.java (or equiv.) code (I suggest putting this in the
constructor method, as it only has to be called ONCE!)
-
GRADING: 100 pts max:
-
50 pts for handing something decent
-
10 pts. for each of the four tasks above, for upt to 40 pts
-
STYLE: Comment, indent, and name variables and methods
meaningfully (<= 10 pts) See the HW2 file World.java
for a pretty good example (you don't have to be quite as verbose as me.
Also, I'll go easy this first time!)
-
SOLUTION (also
on Instruct Server)
Homework 3 "Life, the Universe, and Anything (in 2-dimensions)"
-
Handed out Monday, Feb. 12, 2001
-
Due: Wednesday, Feb. 21, 2001
-
Tasks:
-
Get the latest version of the Life
code we developed in class.
-
Now be creative. Think of some process in nature, including
the human world, to model.
-
You must use a non-boolean array. In other words, take
our array of booleans from Conway's Life code and substitute an array of
int
for example, or an array of double (floating point numbers), or
better yet, an array of some complex object, such as ...
-
SOLUTION (also
on Instruct Server)
Homework 4 "Sorting, Interfaces, Run-time Analysis"
-
Handed out Monday, March 5, 2001
-
Due: Wed. March 21, 2001
-
Here
is Nate's suggested link for on-line learning applets in general, and for
sorting examples in particular.
-
Tasks:
-
Get the latest version of the sorting code, here
or
on the Instruct server.
-
Get the handout, hardcopy only for now!
-
Follow the instructions, except for the part about doing
three sorting algorithms! You only have to implement two: one
O(n^2) and one fast one O(n lg n). BubbleSort doesn't count!
(I gave that to you!) But if we develop InsertionSort or SelectionSort
in class, you can copy that code verbatim and use that. But you still
have to do a FAST one! That is, QuickSort (see hardcopy for version
in Pascal), MergeSort, or HeapSort (on second thought, don't try HeapSort!).
-
Your incentive here is to get a fast sort working and to
show its superiority to a slow sort.
-
So do some runs with very large arrays, much more than 1000,
and note the differences in sort times. Graph these roughly on a
piece of paper and hand that in too!
-
And hand in your code the old fashioned way! (I mean
WebCT)
-
Suggestions for getting started:
-
This is a pretty big assignment. So start small.
You have to first get ALL of the files, and keep them in one folder.
If you miss a file, you will have to figure out which one later!
-
Next familiarize yourself A BIT with the code (you don't
need to read it all at once) by running it, remember this is an applet,
so we have to recall how to run one (e.g., you need an .html file, you
extend panel_applet, etc.)
-
Note how the applet runs BubbleSort. Now try adding
a second sort to the array of sorts.
-
First copy the file "BubbleSort.java" (using Save As, or
whatever). Rename it (file AND class, of course) your own.
-
Next figure out how to insert it into the array of sorts.
Don't worry about changing the code; just let it implement BubbleSort even
though it is called something different now.
-
Then run the whole applet and compare the two sorts (they
should both produce identical behavior!).
-
Now you can go and modify the sorting code!
-
SOLUTION (also
on Instruct Server)
-
Homework 5 "Linked Lists (of Objects) , Part A, Insert"
-
Handed out Wednesday, April 11, 2001
-
Due: Thursday. , April 19, 2001
-
Here
is some useful code. The Controller.java
class shows how to actually use the linked list class. Note that
this is with doubles (floating point numbers with double precision) being
stored in the nodes. You have to store prisonerA's there! (Hence
you have to modify the classes AList and Node.)
-
Here
are prisoners to be tested. Some are "bad" (they will not compile
or they will cause a run-time error). As we find these, I will put
them in the "Bad Prisoners" folder! Let me know who is bad.
I will keep updating these folders. The file Tournaments.java
contains the controller class that we developed in lecture, which runs
some PD tournaments using the submissions for Exam 2, by putting them in
an array, NOT a linked list (it is your job to use a linked list
here!).
-
Goals:
-
Tasks:
-
Get the latest version of the sorting code, (link just above,
or the Instruct server)
-
Take the linked list code, which is in the classes AList
and Node, and modify it so it will store objects of type PrisonerA.
-
Write an application that creates a linked list (empty at
first of course), then adds X copies of each of everybody's PrisonerA
classes
to the FRONT OF THE LIST list (note,
you must modify the existing method AList.add(blah blah)
since it
currently adds nodes to the END of the list).
-
Now add code to print the list (i.e., the Prisoner's names)
to the graphics window.
-
Turn in your source code!
-
HELPFUL HINTS:
-
You must modify the node and
the Alist classes to store objects of type prisonerA (the
interface, which you can treat like a class when you are USING it, as we
are here), rather than storing double (precision floating point
numbers).
-
You could add methods like these to
give you the functionality you need. Note how this offloads
the controller class from having to do all that much:
-
SOLUTION (also
on Instruct Server)
-
Homework 6 "Linked Lists (of Objects), Part B, Delete"
-
Handed out Wednesday, April 11, 2001
-
Due: Wednesday, April 25, 2001
-
Here
is some useful code. The Controller.java
class shows how to actually use the linked list class. Note that
this is with doubles (floating point numbers with double precision) being
stored in the nodes. You have to store prisonerA's there! (Hence
you have to modify the classes AList and Node.)
-
Here
are prisoners to be tested. Some are "bad" (they will not compile
or they will cause a run-time error). As we find these, I will put
them in the "Bad Prisoners" folder! Let me know who is bad.
I will keep updating these folders. The file Tournaments.java
contains the controller class that we developed in lecture, which runs
some PD tournaments using the submissions for Exam 2, by putting them in
an array, NOT a linked list (it is your job to use a linked list
here!).
-
Goals:
-
Tasks:
-
Tasks 1 through 4 from HW5 above, PLUS:
-
Now add code to run a tournament between the first prisoner
in the list and the next prisoner.
-
Whoever loses the tournament, as specified (see Tournaments.java),
delete them from the list.
-
Continue performing the previous two steps until the list
is down to one winner. Display that winner!
-
In between rounds, keep displaying the current list, with
a pause in there so we can watch the gradual progress of the game.
-
Turn in your source code!
-
SOLUTION (also
on Instruct Server)
PROGRAMMING
Language: Java
LINKS:
Platform: NMU IBM ThinkPad
TESTS AND QUIZES
-
Take Home Exam 1
-
Take Home Exam 2: The Prisoners' Dilemma
-
Handed out Wed. 3/38/01. Due
Fri. 3/31/01.
-
See class handout for background on
the game, most importantly the PAYOFF MATRIX!
-
Positive Payoff matrix, where
higher payoffs are BETTER! Note that payoffs are in pairs:
(A,s payoff, B's payoff)
PLAYER |
|
B
|
|
|
|
Cooperate
|
Defect
|
A
|
Cooperate
|
3 ,
3
|
0
, 5
|
|
Defect
|
5
, 0
|
1 ,
1
|
-
For the prisoner metaphor to work,
think of this: each prisoner gets 5 years MINUS the number in the
payoff. Thus if A gets payoff 1, he/she spends 4 YEARS in prison.
With a payoff of 5, one would get off scot free!
-
Get a copy of the INTERFACE here,
-
Write a class that IMPLEMENTS the interface.
-
Compile it, and turn in just
the .class file to WebCT.
-
GRADING: (tentative,
rough guideline 'though)
-
Compiles and mplements the interface
(50 pts.)
-
Ranking in round-robin tournament,
against the world
-
Single round (10 points)
-
Double round (10 points)
-
Triple round (10 points)
-
100 rounds (10 points)
-
Cooperation with self. ( I will
simply run your prisoner against itself for various numbers of rounds).
(10 points)
-
Take Home Exam 3: Linked Lists (swapping nodes)
-
Handed out Mon. 4/16/01. Due
Wed 4/18/01.
-
Show me how a "swap()" method in the
node class might work:
-
Assume a method in Node class,
called public void swap(), that simply swaps the next two nodes
in the list.
-
Pencil and paper:
-
draw for me a linked list, you know,
with boxes and arrows, depicting a list of perhaps 5 or 6 nodes.
Use String as the data type stored in each node (any strings will do).
-
Now re-draw the arrows to show the
same list after a swap. Assume we asked the second node to swap the
next two.
-
Now write the code for the method
swap(). Remember, this goes in Node class, and a node
only has a pointer to the next Node.
-
STRONG SUGGESTION!! For
better chance of partial credit, and to help you understand this stuff
and figure it out WIHTOUT having to actually code it up and run/debug
for hours, do THIS: As you write the
code to do the node swapping, next to each line (leave some space between
lines!) DRAW the linked list again, with boxes and arrows and data values,
as they would look AFTER the ine of code executes. I think this might
be the ONLY way to keep track of what is going on! At least,
for someone like me.
-
Hand -in your piece of paper to
me or my mailbox.
FINAL
-
FINAL PROJECT( Substitute for Final Exam)
-
This option is now open to anyone
in the class!
-
Handed out Tuesday, April 17, 2001
-
Due: Thurs., April
26, 2001 (before the final exam!)
-
Tasks:
-
Conduct Round Robin tournaments, as in the array version
of the code.
-
Put five copies of each class of prisoner (e.g., "TB") into
the list (it doesn't matter where in the list).
-
After the tournament, eliminate the lowest scoring player
by deleting them from the list.
-
Then do it all over again, re-initializing scores to zero.
-
Continue until only one player is left.
-
Display a list of the names currently in the list, in a window.
-
SUGGESTION: Keep track of scores in the nodes (i.e.,
add a state var to the Node class).
-
Turn in your source code!via WebCT
-
COMPREHENSIVE EXAM:
-
Thursday, April 26, 2001, 8:00 AM -9:50, in NSF 1205 (our usual classroom)
-
Open book, open notes
-
Example
questions
-
Mostly Pencil and paper
-
Part of it will be online
-
Topics
-
THE EXAM ITSELF!!