-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetterAvg.java
More file actions
77 lines (62 loc) · 1.64 KB
/
LetterAvg.java
File metadata and controls
77 lines (62 loc) · 1.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.io.IOException;
import java.util.*;
public class LetterAvg extends MesoInherit
{
//char for first letter
private char firstLetter;
/**
* ArrayList that holds the names of the stations that begin with the specified char
*/
private ArrayList<String> nameOfStations = new ArrayList<String>();
/**
*
* @param firstLetter recieves the letter that will be compared in numberOfStationWithLetterAvg() to find the stations that begin with the letter
* @throws IOException
*/
public LetterAvg(char firstLetter) throws IOException
{
readStations();
this.firstLetter = firstLetter;
}
/**
* This method compares compares the first letter of the stations in the array list to firstLetter.
* It also adds the stations that do begin with the letter.
* @return an int containing the amount of stations that start with firstLetter.
*/
public int numberOfStationWithLetterAvg()
{
int numStations = 0;
char[] toCompare = new char[0];
String station;
for(int i = 0 ; i < stations.size(); i++ )
{
toCompare = stations.get(i).toCharArray();
station = stations.get(i);
if(toCompare[0] == (this.firstLetter))
{
this.nameOfStations.add(station);
numStations++;
}
}
return numStations;
}
/**
* Return the class information in the proper format
*/
public String toString()
{
String toPrint = String.format("\nThey are:\n");
for(int i = 0; i < nameOfStations.size(); i++)
{
if(i < (nameOfStations.size() - 1))
{
toPrint += nameOfStations.get(i) + "\n";
}
else
{
toPrint+= nameOfStations.get(i);
}
}
return toPrint;
}
}