Java REVIEW TOPIC 02 – IF STATEMENTS LESSON WORK QUESTION 1
- DIVISIBILITY Create
a program that asks the user for a number and outputs whether that number can
be divided by three or not. Hint: If a number modded
by 3 gives a remainder of zero, then it is divisible by three. Sample I/O #1: Enter a number. 36 The number 36 is divisible by 3. Sample I/O #2: Enter a number. 998 The number 998 is not divisible by 3. Save
your work inside a file called Q1.java inside the folder called Topic02. QUESTION 2
- THAT’S ODD Create
the classic odd or even program
that asks the user for a number and outputs whether that number is an even
number or an odd number. Sample I/O #1: Enter a number. 11 You are odd. Sample I/O #2: Enter a number. 14 Wow, you are not as odd as I thought.
:) Save
your work inside a file called Q2.java inside the folder called Topic02. QUESTION 3
– IN OR OUT Create
the program that gets a point value from the user and outputs whether or not
that point is inside the green rectangle seen the image below. Sample output: Enter the value of x. 7 Enter the value of y. 2 The point (7, 2) is outside of the
rectangle. Save
your work inside a file called Q3.java inside the folder called Topic
02. QUESTION 4
– RANDOM REMINDER Write
a program that generates a random number between 1 and 6 inclusively. Test your program many times to make sure
that each possible value is generated at least once. You
can use the random function in the Math class to generate a random number. Save
your work inside a file called Q4.java inside the folder called Topic
02. QUESTION 5
– TAX BRACKET In
Canada (and in many other parts of the world), a person’s income is
taxed. This is called income tax. The amount of income tax you pay is based
on the amount of money you make in a calendar year. Furthermore, the amount of money you make
is taxed at different rates based on brackets. Here
are the tax brackets we will use for this problem:
You
will write a program that will ask a user for their income and the program
will output the amount of income tax they must pay based on the above tax
bracket table. Save
your work inside a file called Q5.java inside the folder called Topic
02. GOT EXTRA TIME? If
you have extra time, take a few minute to look up Ontario and Canada’s income
tax brackets. Unfortunately, they do
not match so you would have to calculate the provincial income tax and the
federal income tax separately. If
you have time, write the program that would do this. If
you did do this, save your work inside a file called Q5B.java inside the
folder called Topic 02. QUESTION 6
– VARIANT CRAPS GAME The
program in the previous question can be used to represent the rolling of a
6-sided dice. Create
a program that simulates two die being rolled. When the total is either 7 or 11, the
program outputs “Winner winner chicken
dinner”. If the die are
both the same, the program outputs “Roll again”. Otherwise, it outputs “You lose.” Save
your work inside a file called Q6.java inside the folder called Topic
02. |