Page 144 - CA_Blue( J )_Class10
P. 144
Ans. if(a==1)
System.out.println("A is one");
else if(b==2)
{
System.out.println("B is two");
}
else
System.out.println("C is three");
D. Assertion and Reasoning based questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true, and R is the correct explanation of A.
b. Both A and R are true, but R is not the correct explanation of A.
c. A is true, but R is false.
d. A is false, but R is true.
1. Assertion (A): The if-else construct in Java allows the execution of exactly one block of code from multiple alternatives.
Reason (R): The if-else construct evaluates multiple boolean expressions and executes all blocks of code whose conditions are
true.
2. Assertion (A): The switch statement can only be used with primitive data types and enums.
Reason (R): The switch statement in Java cannot handle strings or objects.
3. Assertion (A): The ternary operator in Java is used as a shorthand for the if-else statement.
Reason (R): The ternary operator can only be used when the result of both expressions is of the same type.
Ans. 1. c 2. c 3. a
21 st
E. Case-based questions. Century #Experiential Learning
Skills
1. Debagni is developing a shopping application. She needs to apply a discount based on the total purchase amount. The discount
rules are as follows:
- If the total purchase is less than Rs. 50, no discount.
- If the total purchase is between Rs. 50 and Rs. 100, apply a 10% discount.
- If the total purchase is more than Rs. 100, apply a 20% discount.
Debagni writes the following code to implement these rules:
double totalPurchase = 85.0;
double discount = 0.0;
if (totalPurchase < 50)
{ discount = 0.0; }
else
if (totalPurchase <= 100)
{ discount = 0.10; }
else
{ discount = 0.20; }
double finalPrice = totalPurchase - (totalPurchase * discount);
System.out.println("Final Price: Rs." + finalPrice);
What will be the output of the code?
a. Final Price: Rs. 85.0 b. Final Price: Rs. 76.5
c. Final Price: Rs. 68.0 d. Final Price: Rs. 80.0
2. John is creating a grading system for his school's report card application. The grading rules are as follows:
- If the score is 90 or above, the grade is 'A'.
- If the score is between 80 and 89, the grade is 'B'.
142142 Touchpad Computer Applications-X

