In this IB Computer Science lesson you will be learning about:
Comparisons are joined together using the following operators
Example:
An AND comparison needs both comparisons to be TRUE to produce another TRUE
An OR comparison needs at least one of the comparisons to be TRUE in order to produce a TRUE
A NOT comparison checks if a comparison is not TRUE
Here is a program that asks the user to enter a number then checks if a number is less than that
Sample Input and Outputs
Both comparisons were true so the overall result of the if statement was true
The first comparison was false so the overall result of the if statement was false
The second comparison was false so the overall result of the if statement was false
Here is a program that gives the user a choice of colors to pick from and outputs a fun message
Sample Input and Outputs
First Comparison was true so the if statement executed
Both Comparisons were false so the else statement executed
IB Computer Science Java Compound Comparison Output
Strings are not generally compared using the double equals size in Java. This is because they are actually objects and some unexpected results might happen. You will learn more about that later. Instead you must use the “equals” or “EqualsIgnoreCase” Method
Equals Method
Checks if two strings are identical. Upper and lower case letters are treated differently.
EqualsIgnoreCase
Checks if two strings are identical. Upper and lower case letters are NOT treated differently.
1. Grade Level
Write a GUI that inputs the students grade (as a percentage) and outputs what Ontario Level they are at.
Level 4 – 80% – 100%
Level 3 – 70% – 79%
Level 2 – 60% – 69%
Level 1 – 50% – 59%
Failure – 0% – 49%
2. Roller Coaster
A roller coaster has certain restrictions. You can ride only if you are taller than 122 cm tall or have a mature individual older than 16.
Ask the user for 2 things:
Output if they are allowed to ride or not.
3. Favorite Color
Rewrite Mr. Rogers Favorite Color program using a String Comparison.
4. Guessing Game GUI – WRITE THIS USING A GUI
Check out our programing in python courses that focus on high school level coding.
These courses are complete with interactive coding lessons, teacher led videos, and more practice questions with complete solutions
Return To International Baccalaureate Computer Science Main Page