I'm supposed to write a program in Java . I'm given a text file containing
I am Hakan. My email address is hakan@cs.uh.edu, and what is your name? Hi my name is Tarikul and my favorite email address is tarikul2000@cs.uh.edu
and im suppossed to take tarikul2000@uh.edu and hakan@cs.uh.edu and organize them acording to whether or not they have a subdomain(the "cs" part there other possibilities) or not and store it into class arrays of type Email and UniversityEmail. I'm to then take a user iput of 0-7 and depending on the input print out a different set of info I've created the classes and but i dont know how i can take the info then sort it. The possible subdomains are 1.art 2. chee 3. chem 4. coe 5. cs 6. egr 7. polsci
this is what i have so far if anyone can help me move foward I appreciate it
import java.io.* ; import java.util.HashSet; import java.util.Scanner; import java.io.PrintWriter; import java.io.FileOutputStream; import java.util.regex.Pattern; import java.util.regex.Matcher; public class Try { public static void main(String[] args) { Email [] storage;// email is a class that was made to store the data storage = new Email [99]; UniversityEmail[] save; save= new UniversityEmail[99]; HashSet<String> hs = new HashSet<>(); Scanner input= null; PrintWriter output= null; try { input= new Scanner("inputemails.txt"); output= new PrintWriter("outputemails.txt"); } catch (FileNotFoundException e) { System.out.print("File not found"); System.exit(0);} String line = null; while(input.hasNextLine()) { fillEmailsHashSet(line, hs); } input.close(); output.close(); } public static void fillEmailsHashSet(String line,HashSet<String> container){ Pattern p = Pattern.compile("([\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Za-z]{2,4})"); Matcher m = p.matcher(line); while(m.find()) { container.add(m.group(1)); } }}
The Email and UniversityEmail are in seperate code chunks i can post if it helps