please Help me out, i'm new in java and i want code for following program.

write a program that takes a series of email addresses as a command-line argument and, after parsing/processing the input, display the addresses separately and in alphabetical order at the command window. For example if the email addresses are provided as a long concatenated string like the following:

[email]myname@yahoo.comyour_pet_name@earthmix.orgwonderful3@badar.edu[/email]

And then the result shown on the command window should be something like:

myname@yahoo.com
wonderful3@badar.edu
your_pet_name@earthmix.org

In order to qualify as an email address acceptable to us, every entry must be conforming to the following criterion:

• The prefix or the user-id (i.e. the characters before @) should contain at least 6 and maximum of 15 characters.
• The domain name (i.e. the characters after @ and before dot) should contain at least 3 and maximum of 8 characters.
• The extension (i.e. the characters after dot) must contain exactly 3 characters.
• The extension must be one of the following three types: com, org and edu.

Any email address not conforming to the above criteria must be ignored and not displayed in the final output. For example if the input string is:

[email]thenameofmyfriend@yahoo.commy_name@usa.netwonderful1@badar.edu[/email]

Then the result shown on the command window should only be:

wonderful1@badar.edu

Recommended Answers

All 6 Replies

Per our forum rules:
Do provide evidence of having done some work yourself if posting questions from assignments.

Please post your current code, specific questions, error messages, pseudocode, or anything to demonstrate that you are making some effort towards solving this yourself if you wish to receive further help with it.

import java.util.regex.Matcher;   
import java.util.regex.Pattern;   

public class EmailParser{   
public static void main(String args[]){       
      String emailAddress = args[0];
      String[] parts = emailAddress.split(".com" || ".org" || ".org");
	for(int i=0; i<parts.length; i++)
      System.out.println(parts[i]);
     }
 private static boolean isValidEmail(String parts[i])
 {  
  Pattern pattern=Pattern.compile("[^@.]{6,15}@\\w{3,8}\\.(com|org|edu)$");
  Matcher matcher = pattern.matcher(parts[i]);   
  return matcher.matches();   
  }  }

The code works well for the constraint/limitations that are given in the program but does't get the the emails containing the command line argument into the separate line in alphabetical order

Are all the email addresses in the first element of the args array?
Your code doesn't test if the the args array to see if it's empty or has more than one element.
How do you detect the end of one domain and the beginning of the next name?
Answer: the extension is fixed at 3 letters

yea all the emails are in the first line with no space b/w them

Any email address not conforming to the above criteria must be ignored

How do you detect the end of one extension and the beginning of the next name if the extension is NOT 3 characters? What if the extension is orgXX?
Without a space after the extension, the XX would be moved to the name of the next address.

The code works well

private static boolean isValidEmail(String parts[i])

This does NOT compile???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.