From e32279092981af29ed97f7d8b7e064a5ae10208e Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Fri, 7 Aug 2026 20:58:22 +0300 Subject: [PATCH] added question --- source/ch4_conditionals.ptx | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/source/ch4_conditionals.ptx b/source/ch4_conditionals.ptx index 904fbf4..1f99114 100644 --- a/source/ch4_conditionals.ptx +++ b/source/ch4_conditionals.ptx @@ -401,6 +401,57 @@ public class Ternary {

In , we are using this ternary operator to assign a value to a based on whether a is even or odd. If a is even, it will be squared; if odd, it will be instead be calculated as 3 * x - 1. This is a concise way to write conditional assignments in Java. However, you might want to use it sparingly, as it can make code less readable if overused or used with complex expressions.

+ + + +

+ Rearrange the blocks to create a Java method that calculates shipping costs. Orders over $100 get free shipping ($0.0), while members pay $5.0 and non-members pay $10.0. +

+
+ + + + public double calculateShipping(double orderTotal, boolean isMember) { + + + public double calculateShipping() + double orderTotal + boolean isMember + { + + + + + + if (orderTotal >= 100.0) { + return 0.0; + } + + + if (orderTotal = 100.0) { + return 0.0; + } + + + + + + else { + return isMember ? 5.0 : 10.0; + } + + + else { + return isMember : 5.0 ? 10.0; + } + + + + + } + + +