1. Define an interface

Define an interface called Measuring Device. Add it to your project in its own Measuring Device.cs source file (Project > Add New Item > Interface). Add the following public method declarations to your new interface:

  • Metric Value. This method will return a decimal that represents the metric value of the most recent measurement that was captured
  • ImperialValue. This method will return a decimal that represents the imperial value of the most recent measurement that was captured
  • StartCollecting. This method will start the device running. It will begin collecting measurements and record them.
  • Stop Collecting. This method will stop the device. It will cease collecting measurements.
  • GetRawData. This method will retrieve a copy of all of the recent data that the measuring device has captured. The data will be returned as an array of integer values.

Comment your new method declarations so developers using your interface know what they are meant to do.

2. Define an enumeration

Define an enumeration called Units. Add it to your project in its own UnitsEnumeration.cs source file. You may do so by adding a new class (Project > Add New Item > Class) called Units Enumeration and changing the empty class declaration generated into an enum declaration ("class Units Enumeration" -> "enum Units"). Make your enumeration publicly accessible, and add values Metric and Imperial to it. Comment your enumeration so its purpose is clear.

3. Define a Device class

Define a class called Device. Add it to your project in its own Device.cs source file. Make it publicly accessible and give it one method:

  • GetMeasurement. This method will return a random integer between 1 and 10 as a measurement of some imaginary object.

Comment your class so developers using it know what it does and how to use it.

4. Create the MeasureLengthDevice class

Define a class called MeasureLength Device. Add it to your project in its own MeasureLength Device.cs source file. This class will implement the Measuring Device interface. You may generate stubs for your implementation methods using the Implement Interface Wizard.

Add the following private fields to your class (as well as any others you deem necessary):

  • units ToUse: Units - This field will determine whether the generated measurements are interpreted in metric (e.g. centimeters) or imperial (e.g. inches) units. Its value will be determined from user input.
  • dataCaptured: integer array - This field will store a history of a limited set of recently captured measurements. Once the array is full, the class should start overwriting the oldest elements while continuing to record the newest captures. (You may need some helper fields/variables to go with this one).
  • mostRecentMeasure: integer - This field will store the most recent measurement captured for convenience of display.

Add a constructor for your class which initializes your fields.

Add a means for units ToUse to be set according to user input.

Give your class access to the Device. GetMeasurement() method you created. Should the relationship between MeasureLength Device and Device be is-a or has-a?

Write function bodies for your interface methods:

  • Metric Value. Return the current value from mostRecentMeasure-convert it if units ToUse is not Metric.
  • ImperialValue. Return the current value from mostRecentMeasure-convert it if units ToUse is not Imperial StartCollecting. Start a timer (using System.Windows.Threading.Dispatcher Timer) to perform a data capture every 15 seconds. The timer will call an EventHandler (hooked up to the Tick event) which should set mostRecentMeasurewith a new value from Device. GetMeasurement() and add that value to the dataCaptured history array. Each time this event occurrs, you will also need to update your form by displaying the new measurement along with a current timestamp. Should your device also capture a value before the first 15 second interval has elapsed?
  • Stop Collecting. Stop the timer that started in StartCollecting
  • GetRawData. Return the contents of the dataCapturedarray. Which element is the oldest one in your history? Do you need to manipulate these values? How will they be presented to the user?

5. Build the user interface

In MainWindow.xaml.cs, create an instance of your MeasureLengthDevice class. This object will be accessed and manipulated by the controls on your form. Where/when should this object be created?

Add controls to your MainWindow form:

Give the user a way to set the units of measurement (units ToUse).

Provide a mechanism to start and stop the measurement cycle (StartCollecting / Stop Collecting). Should your interface change when these controls are clicked? Are all of the control options valid in both states (collecting / not collecting)? What happens when the user tries to use the interface in ways you may not have expected?

Create places (labels) to display the current measurement (mostRecentMeasure) and the timestamp when it was taken.

Create a way to display the most recent measurement in the alternate to the selected measurement units (MetricValue / ImperialValue). That is, if the selected units are metric, show the measurement in imperial, and vice-versa. Which units are being collected? Where/how will you display the converted value

Add a button to display the measurement history (GetRawData). Where/how will you display this list? What did you make GetRawData() return? Does the list start with the oldest value collected? What happens when your history array fills up and older values are overwritten? What happens when your history has not been filled up yet? Does "0" count as an actual history entry? Does your history display the units in which the data was collected?

6. Capture screenshots

Capture an image of your application collecting data and displaying the current measurement in the selected units and the timestamp.

Capture an image of your application displaying the current measurement converted to the alternate units.

Please provide a document with all your code from all your files in the project with proper titles. In addition create a screen capture of your application in the following states:

1) Capturing Data showing the active 'Get Data and the most recent collection in a label on the form with a timestamp.

2) Displaying raw data in the array with a click event from a button on the main form.

3) Displaying data converted to the proper measurement as selected by the user. This should be the show the opposite of the current measurement. For our example, always assume the data coming from the device is in inches and we want to convert to centimeters

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.