-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemp.java
More file actions
59 lines (52 loc) · 1.24 KB
/
Copy pathTemp.java
File metadata and controls
59 lines (52 loc) · 1.24 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
package com.instaclustr.kongo;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
/*
* Temperature objects have a Goods temperature category number (0-4) and associated range.
*/
public class Temp
{
double min = -273;
double max = 1000;
int subCatNum = -1;
// given a category number create a temp object with correct range
public Temp(int subCatNum)
{
this.subCatNum = subCatNum;
switch (subCatNum)
{
case -1: break; // any temp allowed
case 0: max = -20; break;
case 1: min = 2; max = 8; break;
case 2: min = 8; max = 15; break;
case 3: min = 15; max = 25; break;
case 4: min = 1; max = 30; break;
default: break;
}
}
// check if the value provided is in range of this temp
boolean tempInRange(double t)
{
return (t >= min && t <= max);
}
// return a random temp which is always in range
double randomTempInRange()
{
Random r = new Random();
double d = min + (max - min) * r.nextDouble();
return d;
}
// return a random temp which has a probability of being out of range
double randomTemp(double prob)
{
Random r = new Random();
if (r.nextDouble() >= prob)
return randomTempInRange();
else
{
if (r.nextBoolean())
return max + 1;
else return min - 1;
}
}
}