Hi people,
I just need to write the following program, where i need to split the email address and store that in 3 different variables and after that also print those variables on the screen.
Question is this:*
Write a class method that splits up an e-mail address stored in a String variable.
Assume that the address has the form name@domain2.domain1. Store name, domain2, domain1 into variables with these names.
For example, if emailaddress contains the string "strummer@gmail.com", the name variable would be assigned "strummer", domain2 would be "gmail" and domain1 would be "com".
Test if the method is correct by printing the variables name, domain2, domain1 on the screen.
I have written some code below, i have started "Object Oreinted Programming" so im just trying to do it in object oriented context. Im confused, i do not know how to proceed. Theres a split method which i have made in the Mail class which is giving me error, after splitting the string(which i do not know if i have done it the right way), i need to store email address in 3 variables( i do not know how to do that also with the code i have used).
Thirdly i have also made another class named TestMail to test the Mail class which is also incomplete as the Mail
is incomplete.
So what do i need to do to complete the question given above?
Here is the Mail class:
public class Mail{
private String email;
public Mail(String e){
email = e;
}
public Mail(){
email = null;
}
public void splitString(String s){
char[] c = s.toCharArray();
String[] tmp = null;
for(int i=0; i<c.length; i++){
if(c.equals("@") || c[i].equals(".")){
tmp = c.split();
}
}
}
}
TestMail class is this:
public class TestMail{
public static void main(String[] param){
Mail eaddress = new Mail("strummer@gmail.com");
eaddress.splitString();
e.getString("name : "+
}
}
Thanks