169k views
5 votes
Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well all vehicles in its Guzzler line from model years 2004-2007. A boolean variable named recalled has been declared. Given a variable modelYear and a String modelName write a statement that assigns true to recalled if the values of modelYear and modelName match the recall details and assigns false otherwise. Do not use an if statement in this exercise!

User Bob Dust
by
6.0k points

1 Answer

2 votes

Answer:

boolean recalled;

((modelYear>=1999 && modelYear<=2002 && modelName=="Extravagant") || (modelYear>=2004 && modelYear<=2007 && modelName=="Guzzler")) ? recalled = true : recalled =false

Step-by-step explanation:

Using a combination of comparison operators and logical operators, the conditions stated in the question is captured in the code snippet with the boolean variable recalled also declared. Since we are not allowed to use the if statement, we have used the conditional or ternary operator that checks if a condition is true executes the statment that follows the question mark else it executes the statement after the full colon.

User Arenim
by
6.6k points