In: Computer Science
Write a program in Java Using object Orientation Design to determine the status of Mini Van Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door.
** MUST USE constructors and methods. The methods should be instantiated by an object. Use simple main. The first bit Stream must be entered by users. The program needs to be interactive
package edu.vt.cs5044;
public enum Gear {
/**
* (P) Park gear.
*/
PARK,
/**
* (R) Reverse gear.
*/
REVERSE,
/**
* (N) Neutral gear.
*/
NEUTRAL,
/**
* (D) Drive gear.
*/
DRIVE;
}
package edu.vt.cs5044;
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
//
// As 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;
}
package edu.vt.cs5044;
public class MinivanDoor
{
public MinivanDoor()
{
// TODO: Your implementation goes here
}
/**
* Returns true if the door is open; false otherwise.
* TODO: Add more detailed comments
*/
public boolean isOpen()
{
// TODO: Your implementation goes here
return false; // TODO: Replace this placeholder
}
/**
* Returns true if the door is locked; false otherwise.
* TODO: Add more detailed comments
*/
public boolean isLocked()
{
// TODO: Your implementation goes here
return false; // TODO: Replace this placeholder
}
/**
* Returns true if the child-safety lock is engaged; false
otherwise.
* TODO: Add more detailed comments
*/
public boolean isChildSafe()
{
// TODO: Your implementation goes here
return false; // TODO: Replace this placeholder
}
/**
* Returns the current state of the gear shift lever
* TODO: Add more detailed comments
*/
public Gear getGear()
{
// TODO: Your implementation goes here
return null; // TODO: Replace this placeholder
}
/**
* Returns the most recent entry from the event log (or null if log
empty).
* TODO: Add more detailed comments
*/
public LogEntry getLastLogEntry()
{
// TODO: Your implementation goes here
return null; // TODO: Replace this placeholder
}
/**
* Returns the number of entries in the event log.
* TODO: Add more detailed comments
*/
public int getLogEntryCount()
{
// TODO: Your implementation goes here
return 0; // TODO: Replace this placeholder
}
/**
* Returns the event log entry at a given index (or null if index
invalid).
* TODO: Add more detailed comments
*/
public LogEntry getLogEntryAt(int index)
{
// TODO: Your implementation goes here
return null; // TODO: Replace this placeholder
}
/**
* Indicates an activation of the gear shift lever.
* TODO: Add more detailed comments
*/
public void setGear(Gear newGear)
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the child-safety (on or off).
* TODO: Add more detailed comments
*/
public void setChildSafe(boolean engage)
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the dashboard lock button.
* TODO: Add more detailed comments
*/
public void pushLockButton()
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the dashboard unlock button.
* TODO: Add more detailed comments
*/
public void pushUnlockButton()
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the dashboard open button.
* TODO: Add more detailed comments
*/
public void pushOpenButton()
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the inside handle.
* TODO: Add more detailed comments
*/
public void pullInsideHandle()
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the outside handle.
* TODO: Add more detailed comments
*/
public void pullOutsideHandle()
{
// TODO: Your implementation goes here
}
/**
* Indicates an activation of the door closure sensor.
* TODO: Add more detailed comments
*/
public void closeDoor()
{
// TODO: Your implementation goes here
}
}
package edu.vt.cs5044;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
@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.
*
* Don't forget the "@Test" annotation.
*/
@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());
}
}