-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorageData.cs
More file actions
74 lines (63 loc) · 1.68 KB
/
StorageData.cs
File metadata and controls
74 lines (63 loc) · 1.68 KB
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
71
72
73
74
using System;
namespace AutoRecipe
{
public class StorageData : IComparable
{
//Members
int stock;
int capacity;
//Constructor
public StorageData() {
stock = 0;
capacity = 0;
}
//Methods
public void AddStock(int addStock)
{
stock += addStock;
}
public void RemoveStock(int removeStock)
{
stock -= removeStock;
}
public void AddCapacity(int addCapacity)
{
capacity += addCapacity;
}
public int CompareTo(object other)
{
try
{
//Cast
StorageData otherStorage = (StorageData) other;
//Check for zero capacity in either StorageData
if (this.Capacity == 0 || otherStorage.Capacity == 0)
{
return otherStorage.Capacity.CompareTo(this.Capacity);
}
//Return the value with minimum storage usage
return ((double)this.Stock / (double)this.Capacity).CompareTo((double)otherStorage.Stock / (double)otherStorage.Capacity);
}
catch (Exception ex)
{
//If the cast fails, then other is null or is not a StorageData. Either way, this instance should be less.
return -1;
}
}
//Properties
public int Stock
{
get
{
return stock;
}
}
public int Capacity
{
get
{
return capacity;
}
}
}
}