Question: java code 1 - Learn how to use the conditional operator ? : for making decisions within expressions, based on a variable's value. Write an

java code
1- Learn how to use the conditional operator ? : for making decisions within expressions, based on a variable's value.
Write an expression using the conditional operator ? : that evaluates the variable age and prints the message "You are eligible to vote." if age is greater or equal to 18 or prints "You are not eligible to vote." otherwise.
2- Learn how to use nested ternary operators to simplify conditional statements.
Write a statement that evaluates the int variable ages and prints the following, using the ternary operator:
"Child": 0-12 years
"Teen": 13-19 years
"Adult": 20-64 years
"Senior": 65 years and above
3-
In a new loyalty program for a caf, customers are classified into tiers based on the number of coffee cups they've purchased. Each tier rewards customers with different benefits.
Write an expression that evaluates the int variable coffeeCups, and prints one of the following, using the ternary operator:
"None"
"Bronze"
"Silver"
"Gold"
"Platinum"
The following values of coffeeCups define the categories:
None: if the number of coffees is less than 10.
Bronze tier is awarded between 10 cups and 19.
Silver tier is awarded between 20 cups and 29,
Gold tier is awarded between 30 and 39,
Platinum tier is awarded over 39 cups.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!