public override void SetProperty(int i_Property, string i_InputFromUserStr) { eTruckProperties property = (eTruckProperties)i_Property; int inputFromUserInt; float inputFromUserFloat; switch (property) { case eTruckProperties.Model: { Model = i_InputFromUserStr; break; } case eTruckProperties.IsCarryingDangerousMaterials: { if (int.TryParse(i_InputFromUserStr, out inputFromUserInt)) { if (inputFromUserInt == 1) { IsCarryingDangerousMaterials = true; } else if (inputFromUserInt == 2) { IsCarryingDangerousMaterials = false; } else { throw new ValueOutOfRangeException(1, 2, "Please enter 1 - YES, 2 - NO"); } } else { throw new FormatException("You have enterd wrong input!"); } break; } case eTruckProperties.MaxCarryWeight: { if (float.TryParse(i_InputFromUserStr, out inputFromUserFloat)) { MaxCarryWeight = inputFromUserFloat; } else { throw new FormatException("You have enterd wrong input!"); } break; } } }
public override void SetProperty(int i_Property, string i_InputFromUser) { eTruckProperties property = (eTruckProperties)i_Property; int inputFromUserInt; float inputFromUserFloat; switch (property) { case eTruckProperties.Model: Model = i_InputFromUser; break; case eTruckProperties.IsTransportingHazardous: if (int.TryParse(i_InputFromUser, out inputFromUserInt)) { if (inputFromUserInt == 1) { IsTransportingHazardous = true; } else if (inputFromUserInt == 2) { IsTransportingHazardous = false; } else { throw new ValueOutOfRangeException(1, 2, "Please enter 1 - Yes or 2 - No"); } } else { throw new FormatException("You have entered wrong input!"); } break; case eTruckProperties.MaxCarryWeight: if (float.TryParse(i_InputFromUser, out inputFromUserFloat)) { if (inputFromUserFloat > 0 && inputFromUserFloat <= 12000) { MaxCarryWeight = inputFromUserFloat; } else { throw new ValueOutOfRangeException(1, 12000, "Max Volume of Cargo if out of range"); } } else { throw new FormatException("You have entered wrong input!"); } break; case eTruckProperties.VolumeOfCargo: if (float.TryParse(i_InputFromUser, out inputFromUserFloat)) { if (inputFromUserFloat < m_MaxCarryWeight && inputFromUserFloat >= 0) { m_VolumeOfCargo = inputFromUserFloat; } else { throw new ValueOutOfRangeException(0, m_MaxCarryWeight, "Volume if cargo Out of range"); } } else { throw new FormatException("You have entered wrong input!"); } break; } }