Answer:
if (speed < 0){ // check if speed is less than zero(0)
++reverseDrivers; // if it is, increment variable reverseDrivers by 1
}
else if (speed < 1) { // else, check if speed is less than 1
++parkedDrivers; // if it is, increment variable parkedDrivers by 1
}
else if (speed < 40){ // else, check if speed is less than 40
++slowDrivers; // if it is, increment variable slowDrivers by 1
}
else if (speed <= 65){ // else, check if speed is less than 65
++safeDrivers; // if it is, increment variable safeDrivers by 1
}
else { // if none of the conditions above is satisfied
++speeders; // increment variable speeders by 1.
}
Step-by-step explanation:
The code snippet above represents a nested-if..else statement and it is written in Java with the following assumptions:
1. all variables have been declared and initialized.
2. the variables have been wrongly typed as seen in the question. i.e reverse Drivers instead of reverseDrivers, parked Drivers instead of parkedDrivers and so on. Since there can not be spaces in naming variables, these have actually been corrected in the code.
The code contains comments that explain every part of the code. Please go through the comments in the code carefully.
Remember:
i. The comments are the statements written after the double forward slash (//).
ii. Writing ++ before or after a variable increments that variable by 1. This also means adding 1 to that variable. So, for example, for variable parkedDrivers, whether we write ++parkedDrivers or parkedDrivers++, they will both increment the variable by one. Though there are differences between the two, it is still safe to use either one of them in this code.
Hope this helps!