Skip to content

Latest commit

 

History

History
74 lines (49 loc) · 2.37 KB

instructions.md

File metadata and controls

74 lines (49 loc) · 2.37 KB

Instructions

In this exercise you'll be modelling a weighing machine with Kilograms as a Unit.

You have 6 tasks each of which requires you to implement one or more properties:

1. Allow the weighing machine to have a precision

To cater to different demands, we allow each weighing machine to be customized with a precision (the number of digits after the decimal separator). Implement the WeighingMachine class to have a get-only Precision property set to the constructor's precision argument:

var wm = new WeighingMachine(precision: 3);

//  => wm.Precision == 3

2. Allow the weight to be set on the weighing machine

Implement the WeighingMachine.Weight property to allow the weight to be get and set:

var wm = new WeighingMachine(precision: 3);
wm.Weight = 60.5;

//  => wm.Weight == 60.5

3. Ensure that a negative input weight is rejected

Clearly, someone cannot have a negative weight. Add validation to the WeighingMachine.Weight property to throw an ArgumentOutOfRangeException when trying to set it to a negative weight:

var wm = new WeighingMachine(precision: 3);
wm.Weight = -10; // Throws an ArgumentOutOfRangeException

4. Allow a tare adjustment to be applied to the weighing machine

The tare adjustment can be any value (even negative or a value that makes the display weight negative) Implement the WeighingMachine.TareAdjustment property to allow the tare adjustment to be set:

var wm = new WeighingMachine(precision: 3);
wm.TareAdjustment = -10.6;

// => wm.TareAdjustment == -10.6

5. Ensure that the weighing machine has a default tare adjustment

After some thorough testing, it appears that due to a manifacturing issue all weighing machines have a bias towards overestimating the weight by 5. Change the WeighingMachine.TareAdjustment property to 5 as its default value.

var wm = new WeighingMachine(precision: 3);

// => wm.TareAdjustment == 5.0

6. Allow the weight to be retrieved

Implement the WeighingMachine.DisplayWeight property which should return a string showing the weight after tare adjustment, with the correct precision applied, and the unit added. Note that: display-weight = input-weight - tare-adjustment

var wm = new WeighingMachine(precision: 3);
wm.Weight = 60.567;
wm.TareAdjustment = 10;

// => wm.DisplayWeight == "50.567 kg"