public static Kilogram CreateNewKilogram(double value, Kilogram firstMass, Kilogram secondMass) { if (firstMass.MaxValue == null && secondMass.MaxValue != null) // Takes the max & min value from the first mass { double newMin = (double)secondMass.MinValue; double newMax = (double)secondMass.MaxValue; return(new Kilogram(value, newMin, newMax)); } else if (firstMass.MaxValue != null && secondMass.MaxValue == null) // Takes the max & min value from the second mass { double newMin = (double)firstMass.MinValue; double newMax = (double)firstMass.MaxValue; return(new Kilogram(value, newMin, newMax)); } else if (firstMass.MaxValue == null && secondMass.MaxValue == null) // None of the masses has a range set { return(new Kilogram(value)); } else // Takes the highest max value and the lowest min value from both masses { double newMin = Math.Min((double)firstMass.MinValue, (double)secondMass.MinValue); double newMax = Math.Max((double)firstMass.MaxValue, (double)secondMass.MaxValue); return(new Kilogram(value, newMin, newMax)); } }
// For when adding a value to an existing mass, instead of two masses together public static Kilogram CreateNewKilogram(double value, Kilogram kilogram) { if (kilogram.MaxValue != null) { double newMin = (double)kilogram.MinValue; double newMax = (double)kilogram.MaxValue; return(new Kilogram(value, newMin, newMax)); } else { return(new Kilogram(value)); } }