This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericListItem.cs
70 lines (60 loc) · 1.97 KB
/
GenericListItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Consumables_Compare
{
public class GenericListItem : IEquatable<GenericListItem>, IComparable<GenericListItem>
{
//Constants
public const string GRAM = "g";
public const string CENTIMETER = "cm";
public const string MILLILITRE = "ml";
public string Unit;
public double Price, UnitValue;
double PricePerUnit
{
get { return Price / UnitValue; }
set { }
}
public string Name;
public GenericListItem(string name, double price, double unitValue, string unit)
{
Name = name;
Price = price;
UnitValue = unitValue;
Unit = unit;
}
public override string ToString()
{
return Name + " Price Per " + Unit + ": " + PricePerUnit;
}
public override bool Equals(object obj)
{
if (obj == null) return false;
GenericListItem objAsItem = obj as GenericListItem;
if (objAsItem == null) return false;
else return Equals(objAsItem);
}
public int SortByNameAscending(string name1, string name2)
{
return name1.CompareTo(name2);
}
public int CompareTo(GenericListItem compareItem)
{
// A null value means that this object is greater.
if (compareItem == null) return 1;
else return this.PricePerUnit.CompareTo(compareItem.PricePerUnit);
}
public override int GetHashCode()
{
return Convert.ToInt32(PricePerUnit);
}
public bool Equals(GenericListItem other)
{
if (other == null) return false;
return (this.PricePerUnit.Equals(other.PricePerUnit));
}
}
}