Chapter Table of Contents
Ch. 6 ConditionalsSection Table of Contents
Chapter Table of ContentsSection Table of ContentsPracticeGradeEven or Odd?Old Enough to Drive?Enhance Billing ProjectPick Your Path
Practice
Grade
Create a class called Grade. In the main method, prompt the user to enter a test score as a percent. Then, print out the letter grade that that score would receive.
π» Template code
Β
Even or Odd?
Use the modulus operator (%) to check whether an inputted number is even or odd.
π» Template code
Β
Old Enough to Drive?
Create a program called Drive. It should do the following:
- Prompt the user to enter their age
- Create 3 boolean expressions isMinor, isAdult, and isSenior. A person is a minor if they're under 18. They are an adult if they're 18-64 years old. They are a senior if they're 65+.
- Print the age group the user is in.
- Print whether the user can drive. An adult or senior can drive, while a minor cannot.
Β
Example output:
Enter your age: 45 You are an adult. Old enough to drive!
π» Template code
Β
Enhance Billing Project
Adjust the billing project so that the program asks the user the name of the item and the price of the item. Next, if the price is greater than $10, then apply a 5% off discount, otherwise if the price is greater than $25, apply a 10% off discount. Then print the name of the item, original price, discount amount, subtotal (discounted price), tax (8% of the discounted price), and total (subtotal + tax).
Β
Example output:
Enter the name of the item: Pizza Enter the price of the item: $12 RECEIPT Item: Pizza Price: $12.00 Discount $0.60 --------------------- Subtotal: $11.40 Tax: $0.96 Total: $12.36
Β
In order to achieve the output above, you will need to use String formatting to ensure that monetary amounts are displayed to 2 decimals of precision. You can read more about that here. If you donβt know how to use String formatting, thatβs ok too, just print things normally.
π» Template code
Β
Pick Your Path
Create a simple pick your path game where you give the user a scenario and different actions they can take. You should have at least 3 scenarios. Use your imagination to think of something cool! Below is a video example for the pick your path program.
π» Template code
Β
Previous Section
6.4 If and ElseNext Section
Chapter 6 QuizΒ
Copyright Β© 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.