From 46e7e227229d79bdee23a2b3ca371b9efd24706d Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Fri, 21 Mar 2025 09:36:40 +0100 Subject: [PATCH] completed everything --- Supermarket/Product.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Supermarket/Product.cs b/Supermarket/Product.cs index 862cc4c..f2b2198 100644 --- a/Supermarket/Product.cs +++ b/Supermarket/Product.cs @@ -75,7 +75,7 @@ public abstract class Product /// True if the bar code is valid, false otherwise 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'; } ///