CS 145 Lab 6
Please submit your completed lab 5 checkpoints in the first 20 minutes of this lab.
In lecture we’ve explored the logical operators &&, ||, and !. These operators are as important to a programmer as a screwdriver and hammer are to a mechanic. Do whatever you can to learn their use. Like this checkpoint.
Suppose you have the following variables are at your disposal, all describing some individual person:
Checkpoint #1: craft expressions for the following derived attributes of this person. You are encouraged to verify the correctness of your expressions using a truthtable.
- A person is eligible for benefits if he/she works half-time (20 hours) or more on average each week.
boolean isBenefitsEligible =
- A person is a teenager if he/she is between 13 and 19 years old, inclusively.
boolean isTeenager =
- A person is a bachelor if he is an unmarried man.
boolean isBachelor =
- A person is busy if he/she has children or typically works over 45 hours a week on average.
boolean isBusy =
- See the variable name.
boolean notBornInOctober1990 =
- A person goes to Starbucks if he/she earns over $30,000 or drinks coffee.
boolean goesToStarbucks =
- A person can have children if he is male. A female can also have children if she is less than 45 years old and does not drink coffee.
boolean canHaveChildren =
Though boolean expressions are interesting and useful in and of themselves, they are almost always used as gatekeepers for loops (which execute 0 or more times) and conditional statements (which execute 0 times or 1 time). Solve one of the following problems, both of which require some conditional gatekeeping.
- Roll a 6-sided die some large number of times. (At least 100000. Make the number easily variable.) Determine the die’s fairness by reporting how many 1s were rolled, how many 2s, 3s, 4s, and so on.
- Shoot a projectile along its parabolic path, sampling the motion every
tDeltaseconds and printing its position. Start the projectile from the origin. For time
t, the projectile’s x-position is px = vx * t, where vx is the velocity along the x-axis. The projectile’s y-position is py = -4.9 * t ^ 2 + vy * t. Stop the motion after 10 seconds (it exploded) or it hits the ground (y = 0). Print each sample position on its own line in the form “(x, y)” and visualize the results here.
Checkpoint #2: show your instructor or TA your working code and output.
- Start homework 2.