Minivan Locks

(Thanks to Cay Horstmann for this problem.)

A minivan has two sliding doors. Each door can be opened by either a dashboard switch, its inside handle, or its outside handle. However, the inside handles do not work if a child lock switch is activated. In order for the sliding doors to open, the gear shift for the transmission must be in "Park", and the master unlock switch must be activated. (Cay Horstmann is the long-suffering owner of just such a vehicle.)

Your task is to simulate a portion of the control software for the vehicle. The input is a sequence of values for the switches and the transmission's gear shift, in the following order:

A typical input would be 0, 0, 0, 1, 0, 1, 0, 0, "P"

For this assignment:

  1. Write a Minivan class that has nine instance variable: eight int values of 0 or 1 for the switches, and one String value for the transmission setting.
  2. Write a method setSwitches() that takes nine values as parameters and sets the minivan's switches to those states.
  3. Write a method checkDoors which returns one of the following results: "left door open", "right door open", "both doors open", or "both doors closed".

Call the methods from your main() program with a series of test values to demonstrate that they work.

Test cases

Calling setSwitches(0, 0, 0, 1, 0, 1, 0, 0, "P") and then checkDoors() should return the result left door open

Calling setSwitches(1, 1, 0, 1, 1, 1, 1, 1, "R") and then checkDoors() should return the result both doors closed

Calling setSwitches(0, 1, 1, 0, 0, 0, 0, 0, "P") and then checkDoors() should return the result both doors closed

Calling setSwitches(0, 1, 1, 1, 0, 0, 0, 0, "P") and then checkDoors() should return the result right door open

Calling setSwitches(1, 0, 1, 1, 0, 0, 0, 1, "P") and then checkDoors() should return the result both doors open

Other tests:

Test 1: the van is not in Park
setSwitches(0,1,1,0,1,0,0,0,"3")
Expected result: both doors closed

Test 2: the van doesn't have the masterUnlock engaged
setSwitches(0,1,1,0,1,0,0,0,"P")
Expected result: both doors closed

Test 3: right side dash switch engaged
setSwitches(0,1,1,1,0,0,0,0,"P")
Expected result: right door open

Test 4: right inside door switch engaged with child lock activated
setSwitches(0,0,1,1,0,0,1,0,"P")
Expected result:  both doors closed

Test 5: right inside door switch engaged with child lock open
setSwitches(0,0,0,1,0,0,1,0,"P")
Expected result:  right door open

Test 6: left and right doors open from outside handles
setSwitches(0,0,0,1,0,1,0,1,"P")
Expected result:  both doors open