completed everything

This commit is contained in:
MarcUs7i 2025-03-21 09:36:40 +01:00
parent 05406dafc8
commit 46e7e22722

View file

@ -75,7 +75,7 @@ public abstract class Product
/// <returns>True if the bar code is valid, false otherwise</returns>
public static bool IsBarcodeValid(string? barcode)
{
if (barcode == null)
if (string.IsNullOrEmpty(barcode) || barcode.Length != 8)
{
return false;
}
@ -101,14 +101,14 @@ public abstract class Product
{
break;
}
int digit = int.Parse(barcode[i].ToString());
int digit = barcode[i] - '0';
weight += i % 2 == 0 ? digit * evenWeight : digit * oddWeight;
}
int calculatedCheckDigit = 10 - (weight % 10) % 10;
int calculatedCheckDigit = (10 - (weight % 10)) % 10;
return calculatedCheckDigit == int.Parse(barcode[^1].ToString());
return calculatedCheckDigit == barcode[^1] - '0';
}
/// <summary>