-
Notifications
You must be signed in to change notification settings - Fork 0
/
CatInfoGenerator.java
87 lines (59 loc) · 2.8 KB
/
CatInfoGenerator.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
82
83
84
85
86
87
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
public class CatInfoGenerator {
private static final int CAMPUS_RADIUS = 250;
private static final int MAX_MONTHS = 60;
private static String[] arrayOfNames = {"Gollum","Spiderman","Mocha","Gora","Zeytin","Spot","Pamuk","Duman","Pasha","Tickles","Kahve","Tekir","Benek","Checkers", "Karamel","Tik Tak", "Havuç", "Blizzard", "Splatter", "Sprite","Hamur","Pofuduk","Popsicle","Ash","Gofret","Latte","Aslan","Patches","Lucky","Fluffy"};
private static ArrayList<String> catNames = new ArrayList<String>( Arrays.asList( arrayOfNames ));
public static ArrayList<String> getRandomNameList( int num ){
ArrayList<String> randomNames = new ArrayList<String>();
Random rand = new Random();
int name_index = 0;
if (num > catNames.size()) {
for (int i = 0; i < catNames.size() ; i++) {
name_index = rand.nextInt(catNames.size());
randomNames.add(catNames.get(name_index));
catNames.remove(name_index);
}
} else {
for (int i = 0; i < num ; i++) {
name_index = rand.nextInt(catNames.size());
randomNames.add(catNames.get(name_index));
catNames.remove(name_index);
}
}
return randomNames;
/* * The method should add num random names from the global static catNames list to a new ArrayList and
* return the random list of names. There should be no duplicates, and you should make sure that num is
* less than the number of names in the catNames list, if not, num should be set to the size of the
* catNames list.*/
}
public static ArrayList<String> getRandomLocationList( int num ){
ArrayList<String> randomLocations = new ArrayList<String>();
int randX;
int randY;
Random rand = new Random();
int locCount = 0; //name counter
while ( locCount < num ){
randX = rand.nextInt( CAMPUS_RADIUS * 2 );
randY = rand.nextInt( CAMPUS_RADIUS * 2 );
//if name not already added to list
if( Math.sqrt( Math.pow(randX,2) + Math.pow(randY,2)) <= CAMPUS_RADIUS * 2 ){
randomLocations.add( randX + "," + randY );
locCount++;
}
}
return randomLocations;
}
public static ArrayList<Integer> getRandomMonthList( int num ){
ArrayList<Integer> randomMonths = new ArrayList<Integer>();
int month;
Random rand = new Random();
for ( int i = 0; i < num; i++ ){
month = rand.nextInt( MAX_MONTHS );
randomMonths.add( month );
}
return randomMonths;
}
}