We’ve had an exam, which is mostly graded but not quite. I will hand them back in lab next Tuesday so that you have time to ask questions. Instead, we will carry on with our discussion of the logical operators. Let’s start with some Blackboxes:
You are having a party for some friends who struggle with jealousy. One friend may not be able to make it. Can you divide the slices of pizza evenly amongst all guests?
You normally don’t answer your phone in the mornings—unless it’s a parent calling you. But you never answer if you’re asleep. The phone is ringing now. Do you answer?
You only drink caffeine-free or diet soda, but not caffeine-free diet soda. Will you drink a given soda?
Here’s your TODO list to complete before we meet again:
Read sections 5.3 through 5.4 in your book. On a quarter sheet, identify 3 compound truths of life using the logical operators &&, ||, and !. For example:
boolean isEdible = isCooked || !isMeat;
Homework 3 is posted, which is due before October 26. Some fixes have been applied to the PDFs and SpecCheckers, so be sure to do a Team / Pull… from the twodee remote in Eclipse. The steps are described in Homework 0, Part 3.
The next lab is posted. We will have a review session for homework 2, which you must attend to receive your Blugolds. Do not attend if you did not receive credit. If you resubmit during the amnesty period, you will have a chance at a second review.
Code.org is a non-profit whose mission is to get kids learning about computer science at a young age. On Friday, October 14, they are holding a workshop at a local elementary school, and I will attend. So, no class Friday!
See you next class!
Sincerely,
P.S. Here’s the code we wrote together in class…
Exercises.java
packagelecture1012;
importjava.io.File;
publicclassExercises {
publicstaticvoid main(String[] args) {
System.out.println(isEvenPizza(24, 6));
}
publicstaticboolean isMathch(int a, int b, int c) {
return a + b == c || b + c == a || a + c == b;
}
publicstaticboolean isEvenPizza(int nSlices, int nFriends) {
return nSlices % nFriends == 0 && nSlices % (nFriends - 1) == 0;
}
publicstaticboolean isDrinkable(boolean isCaffeinated, boolean isDiet) {
// return isCaffeinated ^ isDiet;return isCaffeinated != isDiet;
}
publicstaticboolean isPresident(boolean isRebel, int age, int nYearsResident, int nTerms, boolean isNBC) {
return !isRebel &&
age > 34 &&
nYearsResident >= 14 &&
nTerms < 2 &&
isNBC;
}
}