-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmail.java
67 lines (60 loc) · 1.97 KB
/
Email.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
/**
* This program will take an input in the form of an email id,
* and output the name of the faculty member who uses the id.
*
* @author Justin Rauh
* @version (a version number or a date)
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Random;
public class Email
{
public static void main(String args[]) throws Exception
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
Random rand = new Random();
System.out.println("Greetings Resident\nPlease enter the I.D. of the desired personel.");
String name = br.readLine();
String url = "http://www.ecs.soton.ac.uk/people/";
String fullURL = url+name;
//System.out.println(fullURL);
URL myURL = new URL(fullURL);
BufferedReader in = new BufferedReader(
new InputStreamReader(myURL.openStream()));
String inputLine;
String title = "";
String telephone = "";
System.out.println("Affermative. Searching Now.\n");
int n = rand.nextInt(10)+3;
for(int q=0;q<=n;q++)
{
System.out.print(" .");
Thread.sleep(300);
}
while ((inputLine = in.readLine()) != null){
if(inputLine.contains("<title>"))
{
title = inputLine.substring(11,inputLine.indexOf("|")-1);
}
if(inputLine.contains("property='telephone'>"))
{
int a = inputLine.indexOf("property='telephone'>")+21;
String temp = inputLine.substring(a);
int b = a+temp.indexOf("</a>");
telephone = inputLine.substring(a,b);
}
}
in.close();
System.out.println("\n"+title);
System.out.println(telephone);
}
/**
* Constructor for objects of class Email
*/
public Email()
{
}
}