Question

In: Computer Science

Write a program in Java Using object Orientation Design to determine the status of Mini Van...

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.

  1. A method must be written to indicate the gear shift status and return to main.
  2. A method to display which door is open or can be opened.
  3. A method to show the status of all doors
  4. A method to convert the code to decimal and store in the text file (Character based) as a record.

** 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

Solutions

Expert Solution

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());
}

}


Related Solutions

Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding 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. A method must...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding 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. A method must...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse IDE) The qualifications given are: Residence: The home must be your primary residence. Down payment: They must have a credit score of at least 563. The Java Program needs to do the following. This can all be done in the main() method. Create a boolean variable to store the Residence requirement. Prompt the user to "Enter 1 if the Home will be the primary...
Problem Write a movie management system using object-oriented design principles. The program will read from the...
Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT