Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
Vote
This exercise focuses on the primitive type Boolean.

Download files: Vote.java
Areas: Primitive types.


Vote.java
1// Anna, Bob and Carl all voted on a proposal.
2// There is a boolean variable to represent each person's vote.
3// The variable has the value true if that person voted yes,
4// and false if that person  voted no.
5
6boolean anna = true;
7boolean bob = false;
8boolean carl = true;
9
10boolean vote = anna || bob || carl;
Displaying 10 of 10 lines
View full source


Question 1
What is the programmer trying to do?
Solution

Question 2
Assuming the programmer is trying to set vote to true if all of the people voted yes, is this program correct?
Solution

Question 3
How should the programmer change the last line of code so that vote has the value true if and only if all of the people vote yes?
Solution