CIS 636 Spring 2004 Assignment 6 – Simple Threads in Java 100 points
Assigned: 03/18/2004
Due: 03/25/2004 at the start of class
You may work
individually or in pairs for this assignment. But all work must be the work of
the person/people whose name is on the code! If working in pairs, the
individual contributions should be relatively equal. One possibility is to work
together tonight, then finish separately (to avoid communication difficulties).
Main Assignment:
We are going to use related but unsynchronized threads to
work in (sort of) parallel on a problem.
The task is part of a computer-grading application for multiple choice
tests. The task will be divided up
among threads so that each thread works on a particular student’s test paper (A
TestPaper class is provided – and is available on my WWW page under
assignments). Each thread will
calculate the score for the test paper that it is responsible for. The thread code will need to call code from
the TestPaper class; for instance, the TestPaper class provides a method that
does a lot of work for grading a test paper, and access methods that will
enable storing the number correct, incorrect, and pct correct on the test for
the test paper. You task is to 1) write
a class that provides thread capabilities for this task. The class should
include an instance variable to hold a TestPaper that the thread is to work on.
You may set up your threads either extending Thread or implementing
Runnable. 2) write main that a) kludges
up the contents of the correct answers array, and kludges together an array of
test papers to run the threads on (let my student constructor generate the
student’s answers (saves you work)); b) starts a thread for each test paper; c)
retrieves the results from each thread, and d) produces final summary
results.
Once all of the threads have run (make sure all are done!), calculate the high score, low score, and mean score, and how many students were above the mean. Make sure your code will work even with “unlucky” timing.
Hand in:
To avoid needless long waits, I recommend working
on this on the c: drive, then upon completion, copying it to the a: drive,
testing it there, creating an extra backup for yourself, then (if working in
lab) deleting it from the c: drive.
Miscellaneous:
·
Make sure that your
main demonstrates that your code works.
·
Put YOUR NAME, and
e-mail address, date, AND where to mount filesystem in the IDE, in comments at the beginning of the program.
· Also, comment any significant code to document it (each method, each loop, each if, and each significant calculation should have a comment. In particular, each method needs to have a JAVADOC compatible comment).
· Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line). The IDE should handle this if you hit ENTER and move on to the next line (If you make changes, you may need to TAB to make things right).
· Name your variables meaningfully, to describe their use in the program.
Sample Interaction (I named all test papers John X to aid kludging setup, and didn’t
name threads)
TestPaper: John 1 a d c a a b e d e
c
TestPaper: John 2 a e c c d c e e d
d
TestPaper: John 3 c c c e d e a b b
b
TestPaper: John 4 e c a e d e e d d
b
TestPaper: John 5 c a e c e c c d a
e
TestPaper: John 6 d e c e e e a c c
a
TestPaper: John 7 e a a c d c a b b
d
TestPaper: John 8 e a c a e b c a e
a
TestPaper: John 9 a c e e d b a b a
d
TestPaper: John 10 b e b c b d e b
d d
TestPaper: John 11 e d d a e a e a
d e
TestPaper: John 12 b b b e a a b b
a c
TestPaper: John 13 c a a e d c b e
c c
TestPaper: John 14 d c e e c d b b
d c
TestPaper: John 15 d a b d a d d d
c d
Thread: Thread-1 pct: 0.2
Thread: Thread-2 pct: 0.2
Thread: Thread-3 pct: 0.2
Thread: Thread-4 pct: 0.0
Thread: Thread-5 pct: 0.4
Thread: Thread-6 pct: 0.2
Thread: Thread-7 pct: 0.1
Thread: Thread-8 pct: 0.3
Thread: Thread-9 pct: 0.3
Thread: Thread-10 pct: 0.2
Thread: Thread-11 pct: 0.2
Thread: Thread-12 pct: 0.3
Thread: Thread-13 pct: 0.0
Thread: Thread-14 pct: 0.2
Thread: Thread-15 pct: 0.2
Correct Answers:
a b c d e d c b a e
High Score: 0.4
Low Score: 0.0
Average: 0.20000000000000004
Number above mean: 4: