-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecies.java
More file actions
54 lines (40 loc) · 1.04 KB
/
Species.java
File metadata and controls
54 lines (40 loc) · 1.04 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
import java.util.ArrayList;
public class Species{
private String name;
private String code;
private int[] profile;
public Species(String name, String code)
{
this.name = name;
this.code = code;
}
public String getName()
{
return name;
}
public String getCode()
{
return code;
}
public void setProfile(int[] profile)
{
this.profile = profile;
}
public int[] getProfile()
{
return profile;
}
public String[] getKGrams(int k)
{
int indexPosition = 0;
ArrayList<String> aList = new ArrayList<String>();
while(indexPosition+k <= getCode().length()) //As long as we can fit a string of k size into our array from start indexPosition..
{
aList.add(getCode().substring(indexPosition, indexPosition+k)); //.., we add the substring from indexPosition to indexPosition+k..
indexPosition++; //.. and increment the indexPosition
}
String[] array = new String[aList.size()];
array = aList.toArray(array); //We convert the arrayList to an array
return array;
}
}