-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetDriver.java
More file actions
executable file
·62 lines (54 loc) · 1.75 KB
/
Copy pathSetDriver.java
File metadata and controls
executable file
·62 lines (54 loc) · 1.75 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
import java.io.* ;
import java.util.* ;
public class SetDriver
{
BufferedReader input ;
HashSet<Person> hSet = new HashSet<Person>() ;
TreeSet<Person> tSet = new TreeSet<Person>() ;
public SetDriver()
{
try
{
input = new BufferedReader(new FileReader(new File("PersonList.txt")));
String text = "";
while ((text = input.readLine()) != null)
{
String parts[] = text.split(" ");
String firstName = parts[0] ;
String lastName = parts[1] ;
String[] dateParts = parts[2].split("/") ;
int month = Integer.parseInt(dateParts[0]) ;
int day = Integer.parseInt(dateParts[1]) ;
int year = Integer.parseInt(dateParts[2]) ;
Person person = new Person(firstName,lastName,month,day,year) ;
hSet.add(person) ;
tSet.add(person) ;
}
} catch (IOException io)
{
}
//hSet iteration
Iterator it = hSet.iterator() ;
System.out.println("Iterate through the HashSet:") ;
while(it.hasNext())
{
Person guy = (Person)it.next() ;
System.out.println(guy.getFirstName()+","+guy.getLastName()+" Birth Year:"+guy.getYear()+" Birth Month:"+guy.getMonth()+" Birth Day:"+guy.getDay()+" HashValue:"+guy.hashCode()) ;
System.out.println();
}
System.out.println();
it = tSet.iterator() ;
System.out.println("Iterate through the TreeSet:") ;
while(it.hasNext())
{
Person guy = (Person)it.next() ;
System.out.println(guy.getFirstName()+","+guy.getLastName()+" Birth Year:"+guy.getYear()+" Birth Month:"+guy.getMonth()+" Birth Day:"+guy.getDay()+" HashValue:"+guy.hashCode()) ;
System.out.println();
}
System.out.println();
}
public static void main(String args[])
{
SetDriver app = new SetDriver() ;
}
}