-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCensus.java
More file actions
62 lines (55 loc) · 1.96 KB
/
Census.java
File metadata and controls
62 lines (55 loc) · 1.96 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
package edu.cscc;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Census {
/**
* @author Kelly Waddell
* 10/29/2019 Census class
*/
public static Surname[] loadCensusData(String fname) {
/**
* @parm fname The name of the File
*/
int line = 0; // Keep track of lines of file we've read
//Making a array name namelist with a length of 100
Surname[] namelist = new Surname[100];
File census = new File(fname);
try {
Scanner input = new Scanner(census);
//ignores first line
input.nextLine();
//For loop to print out 100 names
for (; line < 100 && input.hasNext(); line++) {
String c = input.nextLine();
String CensusArray[] = c.split(",");
int rank = 0;
double proportion = 0;
int count = 0;
//Try to make sure numbers format properly
try {
rank = Integer.parseInt(CensusArray[1]);
count = Integer.parseInt(CensusArray[2]);
proportion = Double.parseDouble(CensusArray[3]);
} catch (NumberFormatException e) {
/**
* @exception numberFormatException Throws if the format is incorrect (If it is a string)
*/
e.printStackTrace();
}
/**
* @parm line is the current line of the document
*/
namelist[line] = new Surname(CensusArray[0], rank, count, proportion);
}
} catch (FileNotFoundException e) {
e.printStackTrace();/**
* @exception FileNotFoundException Throws if the file does not exist)
*/
}
/**
* @return Returns the namelist after population
*/
return namelist;
}
}