Your cart is currently empty!
The attached file (attendance.txt) is a list of email addresses you collected for a conference your company hosted. Create a program that will parse each email address by its name and company. (Note: email parser object below). The company should be sorted in the first column and the person’s name associated with the company should…
public class Email {
private String emailStr;
Email() { }
Email(String str) {
emailStr = str;
}
public String parseEmailName() {
String name;
int pos = emailStr.indexOf(‘@’);
name = emailStr.substring(0,pos);
return name;
}
public String parseCompanyName() {
String company;
pos = emailStr.indexOf(‘@’);
dot = emailStr.lastIndexOf(‘.’);
company = emailStr.substring(pos+1, dot);
return company;
}
public String parseExtension() {
int ext;
int dot = emailStr.lastIndexOf(‘.’);
ext = emailStr.substring(dot+1,emailStr.length());
return ext;
}
}
Sample output is listed below:
amzn bob.freed
amzn caitlin.thomas
amzn edward.flak
amzn jill.bennet
amzn mike.reade
fb chris.booker
fb fred.smith
fb jane.bland
fb megan.hill
goog gary.teafer
goog john.kohl
goog larry.page
goog phil.heal
goog zara.war
msft alan.gret
msft darlene.neddle
msft don.shaffer
msft ken.smith
msft sue.flemming
orcl heidi.opal
orcl john.voy
orcl larry.lee
orcl mark.lite
String text = “my text\r\n”;
BufferedWriter output = null;
try {
File file = new File(“example.txt”);
output = new BufferedWriter(new FileWriter(file));
output.write(text);
} catch ( IOException e ) {
e.printStackTrace();
} finally {
if ( output != null ) {
output.close(); // need to close file to write to a file
}
}