43 lines
1 KiB
C#
43 lines
1 KiB
C#
using System.Globalization;
|
|
|
|
namespace Supermarket;
|
|
|
|
public sealed class NonFood : Product
|
|
{
|
|
private readonly List<Review> _reviews;
|
|
|
|
public NonFood(string productName, string barcode, int quantity)
|
|
: base(productName, barcode, quantity)
|
|
{
|
|
_reviews = new List<Review>();
|
|
}
|
|
|
|
public Review[] Reviews => _reviews.ToArray();
|
|
|
|
public double? AverageRating
|
|
{
|
|
get
|
|
{
|
|
if (_reviews.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return _reviews.Average(review => (double)review.Rating);
|
|
}
|
|
}
|
|
|
|
protected override string[] CsvColumnNames => ["Barcode", "ProductName", "Quantity", "AverageRating"];
|
|
|
|
protected override string[] CsvColumnValues => [
|
|
Barcode,
|
|
ProductName,
|
|
Quantity.ToString("F0", CultureInfo.InvariantCulture),
|
|
AverageRating?.ToString("F1", CultureInfo.InvariantCulture) ?? String.Empty
|
|
];
|
|
|
|
public void AddReview(Review review)
|
|
{
|
|
_reviews.Add(review);
|
|
}
|
|
}
|