- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.java
More file actions
Latest commit
71 lines (63 loc) · 1.71 KB
/
Copy pathmain.java
File metadata and controls
71 lines (63 loc) · 1.71 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
packagepackalg;
/**
* PackAlg
* By Arwid Bancewicz, October 19, 2009
*/
// Imports
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;
/**
* PackAlg.java - Main class gathers user input and runs the packing algorithm.
*
* @author Arwid Bancewicz
* @version 1.1, (09/19/09)
* @see PackingAlgorithm
* @see Box
*/
publicclassPackAlg {
/**
* Applies the packing algorithm to user input (no input validation).
* <p>
* The input is formatted as follows:
* <pre>
* (container width) (container length) (container height)
* (number of boxes n)
* [for i : 1..n]
* (box i width) (box i length) (box i height)
* </pre>
* An example:
* <pre>
* 10 12 4
* 2
* 3 4 5
* 4 6 8
* </pre>
* See {@link PackingAlgorithm#statPack(Shape, List)} for output format.
* @see PackingAlgorithm
*/
publicstaticvoidmain(String[] args) throwsIOException {
// Set up input reader
ScannerloInput = newScanner(System.in);
// Read container dimensions
intliCntWidth = loInput.nextInt();
intliCntLength = loInput.nextInt();
intliCntHeight = loInput.nextInt();
// Create container
ShapeloContainer = newBox(liCntWidth, liCntLength, liCntHeight);
// Read box count
intliBoxCount = loInput.nextInt();
// Compile list of boxes from input
List<Shape> loBoxes = newArrayList<Shape>();
while (liBoxCount-- > 0) {
intliBoxWidth = loInput.nextInt();
intliBoxLength = loInput.nextInt();
intliBoxHeight = loInput.nextInt();
loBoxes.add(newBox(liBoxWidth, liBoxLength, liBoxHeight));
}
// Apply packing algorithm to input
PackingAlgorithmloAlg = newPackingAlgorithm();
loAlg.statPack(loContainer, loBoxes);
}
}