CS 122, Winter 2020,
Instructor: Jeffrey Horn
CLASS ANNOUNCEMENTS (Thursday, February 6, 2020)
- What IS New:
- A3 due date is pushed back two days to Friday Feb, 7, 2020. See below.
- Added a link to Java Docs in Lecture Notes below.
- What Was New :
- A3 is up. See below.
- A2 due date is extended to Wed. Jan. 28, 2020 (11:59pm, which is basically midnight!)
- Reminder:
No class today! (Tuesday, 1-21-2020) I will be posting
material (including video lectures) for you to review on your own
time. We will meet again this Thursday at our usual class
time (3pm Th. 1-23-2020)
- Assignment 2 is up. There is a short video that goes with it. Look here.
- If you have not yet sent me your Assignment 1 java code then please do so. (It was due Jan. 20)
- Welcome
to class! Check
out our syllabus (link is below)
- This is where old announcements will go, so that
you won't miss any news!
CONTENTS:
ADMINISTRATIVA
LECTURE NOTES
ASSIGNMENTS
- ASSIGNMENT 1: Finding a
Perfect Square Pyramid
- HANDED OUT: Tuesday, January 14,
2020
- DUE ON: Monday, January 20, 2020 (midnight)
- GOAL:
- Consider
a pyramid of spheres, D levels deep. On the top level, level 1,
there is one sphere. Level 2 has four spheres, in a 2 by 2 grid
(and level 1's sphere is nested in the middle of it). Level 3
consists of nine spheres in a 3 by 3 grid wit level 2's grid centered
on it. Level 4 has 16 spheres in a 4x4 grid. And so
on! The bottom level, level D, has D2 spheres in a DxD grid. So the total number of spheres, N, in the pyramid is N=1+4+9+16+...+D2; a sum of perfect squares from 1 to D!
- Write a
program that finds the depth D' for a pyramid P' such that the total
number of spheres in P' (N') is itself a perfect square!
(Note: there are only two such depths and one of them is the
trivial case D'=1. Find the OTHER such D'!)
- Your program should:
- Print out both the number of spheres N' and the depth D'.
- Calculate
these numbers so that I can plainly see HOW you computed the numbers
when I look are your code. I say this because you might
find a way to calculate D' and N' mathematically. If you do then
I want your code to include the formulae you used. In other
words, if you find the numbers by some other means (e.g., from a
friend, or from the web) then I don't want your code to just print the
numbers! I want to see the calculation or computation IN THE CODE!
- SUBMISSION:
Email me a copy of jour .java source code file as an
attachment. (Please write "CS 122: A1" in the SUBJECT
field.)
- ASSIGNMENT 2: Let's Make a Deal!
- HANDED OUT: Tuesday, January 21,
2020
- DUE ON: Monday, January 27, 2020 (11:59pm) Wednesday, January 29, 2020 (11:59pm)
- GOAL:
Design a software experiment to test the hypothesis that the SWITCH
strategy wins the Let's Make a Deal!" game 2/3 of the time while the
STAY strategy wins 1/3 of the time.
- STEPS:
- Consider the famous problem known as "Let's Make a Deal!" or "The Monty Hall Problem." Here
is my own short video to introduce it (old, I know!). Feel free
to google "The Monty Hall Problem" and find out the fascinating history
of this problem.
- What is so
interesting about this problem is that statistical analysis says that
the best strategy is to switch doors rather than stay with your
original choice (2/3 chance of winning the car versus 1/3).
But this result seems to most (including me!) counter-intuitive, at
first.
- Your
challenge is not to perform a statistical analysis but instead to
program an experiment that actually runs the game N times for both the
SWITCH and the STAY strategies, and then prints the
results. Thus your simulation should experimentally verify
the results predicted by the mathematics.
- Exactly how you do this is up to you. Here is what I require:
- Your code
must print out three numbers (all labeled!): N (the total number
of games simulated), percent of games that SWITCH strategy won the car,
percent of games that STAY strategy won the car. (That's one int
and two floats!)
- Your code must use random numbers. These can be from a pseudo random number generator like what Math.random() uses.
- I want to
be able to be able to read and understand your code well enough that I
can use it as (empirical) proof (or at least as evidence) that SWITCH
is better than STAY. You don't have to go crazy documenting your
code. Your target audience is me. But I want to be sure
that your program implements a valid experiment to test the
hypothesis! (that is, the hypothesis that SWITCH should win about
2/3 of the time STAY about 1/3, in the long run, as N approaches
infinity!)
- SUBMISSION:
Email me a copy of jour .java source code file as an
attachment. (Please write "CS 122: A2" in the SUBJECT
field.)
- ASSIGNMENT 3: Arrays of Integers
- HANDED OUT: Tuesday, January 28,
2020
- DUE ON: Wednesday, Feb. 5 , 2020 (11:59pm) Friday, Feb. 7 , 2020 (11:59pm)
- GOAL: Review arrays, learn basic file input, develop more algorithmic thinking.
- STEPS:
- Grab this code we worked on together in class: ReadIntegersFromFileToArray.java
- Modify the code to do the following: (Note: Total is 200 pt.s)
- Print the largest, smallest, and average values in the file, and the number of values. (40 pt.s)
- Print the two largest values. (20 pt.s)
- Print the five largest values. (20 pt.s)
- Print the k largest values (where k is the FIRST integer in the file). (60 pt.s)
- Do all of the above in a SINGLE PASS through your array. (50 pt.s)
- Use good style: a main comment (5 pt.s) and indentation (5 pt.s)
- Print to the console window. Make sure all of your output val.s are LABELED! (e.g., "Max: 529")
- SUBMISSION:
Email me a copy of jour .java source code file as an
attachment. (Please write "CS 122: A3" in the SUBJECT
field.)
* (Note there are
extra hardcopies of the homeworks in the handout cabinet outside of
room JXJ 2110, the NERL (robotics laboratory), here.)
TESTS AND QUIZES
FINAL EXAM