completed everything
This commit is contained in:
parent
05406dafc8
commit
46e7e22722
1 changed files with 5 additions and 5 deletions
|
|
@ -75,7 +75,7 @@ public abstract class Product
|
||||||
/// <returns>True if the bar code is valid, false otherwise</returns>
|
/// <returns>True if the bar code is valid, false otherwise</returns>
|
||||||
public static bool IsBarcodeValid(string? barcode)
|
public static bool IsBarcodeValid(string? barcode)
|
||||||
{
|
{
|
||||||
if (barcode == null)
|
if (string.IsNullOrEmpty(barcode) || barcode.Length != 8)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -102,13 +102,13 @@ public abstract class Product
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int digit = int.Parse(barcode[i].ToString());
|
int digit = barcode[i] - '0';
|
||||||
weight += i % 2 == 0 ? digit * evenWeight : digit * oddWeight;
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue