forked from rileyalankirk/food-truck-simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomLocations.java
More file actions
61 lines (45 loc) · 1.69 KB
/
RandomLocations.java
File metadata and controls
61 lines (45 loc) · 1.69 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
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Random;
public class RandomLocations {
public static int randomHouseNumber(int min, int max){
int[] numberOf10s = {10,20,30,40,50,60,70,80,90};
int x= (int)((Math.random()*((max-min)+1))+min);
int idx = new Random().nextInt(numberOf10s.length);
int randomHouseNumber = (numberOf10s [idx]);
if (x == 0){
return Integer.parseInt(randomHouseNumber+"");}
else{
return Integer.parseInt(x +""+ randomHouseNumber);}
}
public static String randomStreetName(){
String[] mystring = {"South", "East"};
int idx = new Random().nextInt(mystring.length);
String randomStreat = (mystring [idx]);
return randomStreat;
}
public static String randomStreetNumber(int min, int max){
int num = (int)((Math.random()*((max-min)+1))+min);
if (num ==1)
return num + "st";
else if (num ==2)
return num + "nd";
else if (num ==3)
return num + "rd";
else
return num + "th";
}
public static void main(String[] args) throws Exception{
int min = 0;
int max = 10;
BufferedWriter out = new BufferedWriter(new FileWriter("100RandomLocations.txt"));
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
int howManyBlock = (int) ((Math.random() * ((max - min) + 1)) + min);
out.write(randomHouseNumber(0, 19) + " " + randomStreetName() + " " + randomStreetNumber(1, 19) + " " + howManyBlock);
out.newLine();
}
}
out.close();
}
}