-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.java
81 lines (69 loc) · 2.49 KB
/
Generator.java
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
75
76
77
78
79
80
81
//b6030326 - Callum Simpson
/**
* The Generator class generates coils of rope and customer orders
* Do NOT modify the names and signatures of the two generator methods
*
* @author Rouaa Yassin-Kassab & John Colquhoun
* @since 30/10/2017
* extended by @author
*/
import java.util.ArrayList;
import java.util.List;
public class Generator {
// This variable represents the longest possible length of rope that a customer
// can order
private final int MAX_ORDER_LENGTH = 100;
// These variables represent the longest and smallest possible coils of rope
// that the manufacturers can supply
private final int MIN_ROPE_LENGTH = 100;
private final int MAX_ROPE_LENGTH = 200;
/**
* This method will generate a list of orders of random lengths between the min
* and max order sizes (currently 1 and 100m)
*
* @param numberOfOrders:
* the number of customer orders to generate
* @return a list of customer orders
*/
public List<Integer> generateMultipleOrders(int numberOfOrders) {
//create a array list that will hold orders
List<Integer> orderList = new ArrayList<Integer>();
/*
* Note that for a list of Integers, you can add ints without converting to
* Integers Example: orderList.add (1) will work, you don't need to do
* orderList.add (new Integer(1))
*/
//for every order
for (int i = 0; i < numberOfOrders; i++) {
//generate a random order
int randomOrder = (int) (Math.random() * (MAX_ORDER_LENGTH) + 1);
//add the new random order to the order list
orderList.add(randomOrder);
}
//return the list of orders
return orderList;
}
/**
* This method will generate a list of new coils of rope from the manufacturer
* of random lengths between the min and max order sizes (currently 100 and
* 200m)
*
* @param numberOfCoils:
* the number of ropes to generate
* @return a list of coils of rope supplied by the manufacturer
*
*/
public List<Rope> orderRopeFromManufacturer(int numberOfCoils) {
//create a array list that will hold all the generated ropes
List<Rope> coils = new ArrayList<Rope>();
//for every rope we want to make
for (int i = 0; i < numberOfCoils; i++) {
//generate a random sided rope
int randomCoilLenght = (int) (Math.random() * (MAX_ROPE_LENGTH - MIN_ROPE_LENGTH)) + MIN_ROPE_LENGTH;
//add the rope to the coil list
coils.add(new Rope(randomCoilLenght));
}
//return the list of coils
return coils;
}
}