Question: Complete class using a test unit that manages the sliding door with writing instance variables, accessors, and mutator methods, also use of if statements to

Complete class using a test unit that manages the sliding door with writing instance variables, accessors, and mutator methods, also use of if statements to provide conditional logic. Also write tests to verify the proper operation of your code.

Type a class that monitors and controls the operation of the

sliding door of a minivan.

Rules:

The door can be locked or unlocked at any time, by using a

lock-unlock button on the dashboard.

When the door is closed, the door can only be successfully

opened if:

1. gear shift lever is in park; and

2. door is unlocked.

When is like that, any of the following mechanisms will

successfully open the door:

1. with an open button on the dashboard;

2. handle on the outside of the door; or

3. handle on the inside of the door.

However,

the inside handle mechanism will not open the door if a separate child safety

mechanism has been engaged, regardless of any other conditions. The child

safety mechanism can only be engaged or disengaged while the door is

open.

The door can be closed at any time, and the gear can be changed at

any time.

Also produce an

event log containing all attempts to change the state of the system -effective

or not-

Mutator call must always result in exactly one LogEntry value appended to the event log, even

if no state is actually mutated due to the operational rules. The event

log must be stored as an ArrayList field

System

Description

You will develop a class called Minivan that models the behavior and state of the sliding

door of the minivan. The methods of this class will be invoked by other

systems, displays, and sensors within the minivan to indicate certain requests

or activities. The methods of your implementation must behave according to the

operational rules above. Your class will provide the following public

methods, plus any private instance variables and private methods as needed:

Constructor:

Minivan() initializes

the minivan door system to its default state:

door is closed

door is unlocked

child-safety is disengaged

gear shift lever is in park

event log is empty

Accessors:

isOpen() request

the state of the door

isLocked() request

the state of the door's lock

isChildSafe() request

the state of the child safety feature

getGear() request

the state of the gear shift lever

getLastLogEntry() request

the most recent entry from the event log (returns null if the event

log is empty)

getLogEntryCount() request

the number of entries in the event log

getLogEntryAt(int

index) request the specified log entry event (returns null if the

index is invalid)

Mutators:

setGear(Gear

gear) indicate an activation of the gear shift lever

setChildSafe(boolean

engage) indicate an activation of the child-safety (on or off)

pushLockButton() indicate

an activation of the dashboard lock button

pushUnlockButton() indicate

an activation of the dashboard unlock button

pushOpenButton() indicate

an activation of the dashboard open button

pullInsideHandle() indicate

an activation of the inside handle

pullOutsideHandle() indicate

an activation of the outside handle

closeDoor() indicate

an activation of the door closure sensor

/**

* The minivan door class will check for

*

*

* @author

* @version

*/

public class MinivanDoor

{

// TODO: Add your private fields here,

including the event log

public MinivanDoor()

{

// TODO: Your

implementation goes here

}

public boolean isOpen()

{

// TODO: Your

implementation goes here

return false; // TODO:

Replace this placeholder

}

public boolean isLocked()

{

// TODO: Your

implementation goes here

return false; // TODO:

Replace this placeholder

}

public boolean isChildSafe()

{

// TODO: Your

implementation goes here

return false; // TODO:

Replace this placeholder

}

public Gear getGear()

{

// TODO: Your

implementation goes here

return null; // TODO:

Replace this placeholder

}

public LogEntry getLastLogEntry()

{

// TODO: Your

implementation goes here

return null; // TODO:

Replace this placeholder

}

public int getLogEntryCount()

{

// TODO: Your

implementation goes here

return 0; // TODO:

Replace this placeholder

}

public LogEntry getLogEntryAt(int index)

{

// TODO: Your

implementation goes here

return null; // TODO:

Replace this placeholder

}

public void setGear(Gear newGear)

{

// TODO: Your

implementation goes here

}

public void setChildSafe(boolean engage)

{

// TODO: Your

implementation goes here

}

public void pushLockButton()

{

// TODO: Your

implementation goes here

}

public void pushUnlockButton()

{

// TODO: Your

implementation goes here

}

public void pushOpenButton()

{

// TODO: Your

implementation goes here

}

public void pullInsideHandle()

{

// TODO: Your

implementation goes here

}

public void pullOutsideHandle()

{

// TODO: Your

implementation goes here

}

public void closeDoor()

{

// TODO: Your

implementation goes here

}

}

/**

* The gear shift lever can be placed in any one of these

positions.

*

* IMPORTANT: Please DO NOT modify this file in any way!

*

* @author

* @version

*/

public enum Gear {

/**

* (P) Park gear.

*/

PARK,

/**

* (R) Reverse gear.

*/

REVERSE,

/**

* (N) Neutral gear.

*/

NEUTRAL,

/**

* (D) Drive gear.

*/

DRIVE;

}

/**

* One LogEntry value is added to the event log by each

MinivanDoor mutator.

*

*

* DO NOT modify this file

*

* @author

* @version

*/

public enum LogEntry {

//

-----------------------------------------------------------------------

// Values that indicate a successful state

change request:

//

-----------------------------------------------------------------------

/**

* Door was closed; now open.

*/

DOOR_OPENED,

/**

* Door was open; now closed.

*/

DOOR_CLOSED,

/**

* Door was unlocked; now locked.

*/

DOOR_LOCKED,

/**

* Door was locked; now unlocked.

*/

DOOR_UNLOCKED,

/**

* Child-safety was disengaged; now

engaged.

*/

CHILD_SAFE_ENGAGED,

/**

* Child-safety was engaged; now

disengaged.

*/

CHILD_SAFE_DISENGAGED,

/**

* Gear was any gear other than park; now

in park.

*/

GEAR_PARKED,

/**

* Gear was in park; now in any other

gear.

*/

GEAR_RELEASED,

//

-----------------------------------------------------------------------

// Values that indicate a change request

performed no action

//

-----------------------------------------------------------------------

//

// NOTE: If multiple values apply, you must

use the FIRST one listed below.

//

// For example, if the door is locked, the

gear is not in park,

// and the outside handle is activated, then

the value recorded in the log

// should be OPEN_REFUSED_GEAR rather than

OPEN_REFUSED_LOCKED even though both apply

//

// Another example, if the door is already

locked when a lock request is

// made, the log entry should be

NO_ACTION_TAKEN.

//

//

-----------------------------------------------------------------------

/**

* Open refused; inner handle activated

while child-safety engaged.

*/

OPEN_REFUSED_CHILD_SAFE,

/**

* Open refused; gear is not in park.

*/

OPEN_REFUSED_GEAR,

/**

* Open refused; door is locked.

*/

OPEN_REFUSED_LOCK,

/**

* Child-safe change refused; door is not

open.

*/

CHILD_SAFE_CHANGE_REFUSED,

/**

* Any request that results in no state

change.

*/

NO_ACTION_TAKEN;

}

import static org.junit.Assert.*;

import org.junit.Before;

import org.junit.Test;

//CHECKSTYLE:l

/**

* A starter JUnit test class for the MinivanDoor.

*

* NOTE: Javadocs are NOT required in this file.

* Comments are provided here to help document the example

test cases.

* Please be sure name all of your test methods very

clearly,

* and use in-line comments as necessary.

*

*

* Leave the below "@SuppressWarnings" annotation

intact, to avoid

* Eclipse warnings about Javadocs, and keep the

CHECKSTYLE:OFF comment above.

*/

@SuppressWarnings("javadoc")

public class MinivanDoorTest

{

private MinivanDoor vanDoor;

/*

* Called by JUnit each time it calls any

test method.

* Note the "@Before"

annotation, immediately above the method signature.

* You'll need to use the

"@Test" annotation for all your test methods.

* We'll use this to simply create a new

default instance of MinivanDoor.

*/

@Before

public void setUp()

{

vanDoor = new

MinivanDoor();

}

/*

* Tests all the initial values of the

constructor.

* This also requires most accessor

methods to be implemented properly.

*

*

*/

@Test

public void testConstructorDefaults()

{

// Default setup

assertFalse(vanDoor.isLocked());

assertFalse(vanDoor.isOpen());

assertFalse(vanDoor.isChildSafe());

assertEquals(Gear.PARK,

vanDoor.getGear());

assertEquals(0,

vanDoor.getLogEntryCount());

assertNull(vanDoor.getLastLogEntry());

}

/*

* Test activation of the lock button

with default setup.

* We expect the door to lock

successfully,

* with an event log entry that reflects

this.

*

* Don't forget the "@Test"

annotation.

*/

@Test

public void testLockDoorWithDefaults()

{

// Default setup

vanDoor.pushLockButton();

// ACTION

assertTrue(vanDoor.isLocked());

assertEquals(LogEntry.DOOR_LOCKED,

vanDoor.getLastLogEntry());

}

/*

* Test opening the door with the open

button, after locking the door.

* We expect the door to remain closed

and locked in this case,

* with an event log entry that reflects

this.

*

* Note how we use another test case as

the setup here, so we can be sure

* that the setup itself actually worked

as expected before continuing.

*

* Don't forget the "@Test"

annotation.

*/

@Test

public void

testOpenButtonAfterLockedWithDefaults()

{

testLockDoorWithDefaults();

vanDoor.pushOpenButton();

// ACTION

assertTrue(vanDoor.isLocked());

assertFalse(vanDoor.isOpen());

assertEquals(LogEntry.OPEN_REFUSED_LOCK,

vanDoor.getLastLogEntry());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!