-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBin.java
More file actions
55 lines (42 loc) · 1.34 KB
/
Bin.java
File metadata and controls
55 lines (42 loc) · 1.34 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
import java.util.ArrayList;
public class Bin implements Comparable<Bin> { //This constructor class implements comparable
public int binSize;
public ArrayList<Integer> items = new ArrayList<Integer>();
private static int count = 0;
public int id = 0;
public Bin(int binSize) { //Constructor for Bin class
this.binSize = binSize;
count++;
id = count;
}
public int GetBinSize() { //returns the size of the bin to be used in BinPacking
return binSize;
}
public void AddItem(int addItem) { //Adds the item to the bin and re adjusts the binSize
items.add(addItem);
binSize -= addItem;
}
public String toString() { //toString method for printing out the Bin# and its contents
String myString = "Bin #" + id + ": " + items;
return myString;
}
public int compareTo(Bin myBin) { //used to compare the sizes of bins and determines which is larger or smaller
if (binSize > myBin.binSize) {
return 1;
}
else if (binSize < myBin.binSize) {
return -1;
}
else {
if (id > myBin.id) {
return 1;
}
else if (id < myBin.id) {
return -1;
}
else {
return 0;
}
}
}
}