Project: Calendar-Application
package calendar;
 
 
import java.util.Calendar; 
 
/*
 * To change this template, choose Tools | Templates 
 * and open the template in the editor. 
 */
 
 
/**
 * 
 * @author Adam Jama 
 */
 
public class Contact extends CsvStructure { 
 /**
  * This is the variables needed for creating a new contact  
  *  
  */
 
 private int m_id; 
 private String m_name; 
 private Calendar m_dob; 
 private String m_landphone; 
 private String m_mobilephone; 
 private String m_workphone; 
 private String m_email; 
 private String m_workemail; 
 private String m_website; 
 
 public static final int NO_FIELDS = 9
 public static final int IDX_ID = 0
 public static final int IDX_NAME = 1
 public static final int IDX_DOB = 2
 public static final int IDX_LANDPHONE = 3
 public static final int IDX_MOBILEPHONE = 4
 public static final int IDX_WORKPHONE = 5
 public static final int IDX_EMAIL = 6
 public static final int IDX_WORKEMAIL = 7
 public static final int IDX_WEBSITE = 8
 
 
 /**
  * This gets a dob for a contact 
  * @return Dob 
  */
  
 public Calendar GetDob() { 
  return m_dob; 
 
 /**
  * This sets a dob for a contact 
  * @param Dob 
  */
  
 public void SetDob(Calendar dob) { 
  m_dob = dob; 
 
 /**
  * This gets a email for a contact 
  * @return email 
  */
  
 public String GetEmail() { 
  return m_email; 
 
 /**
  * This sets the Email for a contact 
  * @param email 
  */
   
 public void SetEmail(String email) { 
  m_email = email; 
 
 /**
  * This gets and Id for contact 
  * @return id 
  */
  
 public int GetId() { 
  return m_id; 
 
 /**
  * This sets Id for contact 
  * @param id 
  */
  
 public void SetId(int id) { 
  m_id = id; 
 
 /**
  * This gets Landphone for contact 
  * @return landphone 
  */
  
 public String GetLandphone() { 
  return m_landphone; 
 
 /**
  * This sets a landphone for a contact 
  * @param landphone 
  */
  
 public void SetLandphone(String landphone) { 
  m_landphone = landphone; 
 
 /**
  * This gets a mobilephone number for contact 
  * @return mobilephone 
  */
  
 public String GetMobilephone() { 
  return m_mobilephone; 
 
 /**
  * This sets mobilephone ofr contact 
  * @param mobilephone 
  */
  
 public void SetMobilephone(String mobilephone) { 
  m_mobilephone = mobilephone; 
 
 /**
  * This gets name for contact 
  * @return name 
  */
  
 public String GetName() { 
  return m_name; 
 
 /**
  * This sets name for contact 
  * @param name 
  *  
  */
  
 public void SetName(String name) { 
  m_name = name; 
 
 /**
  * This gets workemail for contact 
  * @return workemail 
  */
  
 public String GetWorkemail() { 
  return m_workemail; 
 
 /**
  * This sets workemail for contact 
  * @param workemail 
  */
  
 public void SetWorkemail(String workemail) { 
  m_workemail = workemail; 
 
 /**
  * This gets workphone for contact 
  * @return workphone 
  */
  
 public String GetWorkphone() { 
  return m_workphone; 
 
 /**
  * This sets workphone for contact 
  * @param workphone 
  */
  
 public void SetWorkphone(String workphone) { 
  m_workphone = workphone; 
 
 
 /**
  * Get the website of the contact 
  * @return website 
  */
 
 
 public String GetWebsite() { 
  return m_website; 
 
 
 /**
  * Set the website of the contact 
  * @param website - the url of the website 
  */
 
 public void SetWebsite(String website) { 
  m_website = website; 
 
 
 /**
  * Constructor for creating a new contact 
  *  
  */
   
 public Contact() { 
  m_id = 0
  m_name = "."
  m_dob = Calendar.getInstance(); 
  m_landphone = "."
  m_mobilephone = "."
  m_workphone = "."
  m_email = "."
  m_workemail = "."
  m_website = "."
 
/**
 * Main Constructor  
 * @param m_id 
 * @param m_name 
 * @param m_dob 
 * @param m_landphone 
 * @param m_mobilephone 
 * @param m_workphone 
 * @param m_email 
 * @param m_workemail 
 * @param website 
 */
 
 public Contact(int m_id, String m_name, Calendar m_dob, String m_landphone 
   , String m_mobilephone, String m_workphone, String m_email,  
   String m_workemail, String website) { 
  this.m_id = m_id; 
  this.m_name = m_name; 
  this.m_website = website; 
  try { 
   if(ValidDob(m_dob)==true
    this.m_dob = m_dob; 
   else 
    throw new Exception(); 
   if (ValidLandphone(m_landphone) == true
    this.m_landphone = m_landphone; 
   else 
    throw new Exception(); 
   if (ValidMobilephone(m_mobilephone)==true
    this.m_mobilephone = m_mobilephone; 
   else 
    throw new Exception(); 
   if (ValidWorkphone(m_workphone)==true
    this.m_workphone = m_workphone; 
   else 
    throw new Exception(); 
   if (ValidEmail(m_email)==true
    this.m_email = m_email; 
   else 
    throw new Exception(); 
   if (ValidWorkemail(m_workemail)==true
    this.m_workemail = m_workemail; 
  catch (Exception e) { 
   e.printStackTrace(); 
  
 
 
 
 
 /**
  * Send contact to CSV File 
  *  
  */
   
 
 @Override 
 public String ToCSV() { 
  String csv = m_id+",\""+m_name+"\","+"\""+Data.FromDate(m_dob)+"\",\""
    m_landphone+"\",\""+m_mobilephone+"\",\""+m_workphone+"\","+"\""
    m_email+"\",\""+m_workemail+"\""+",\""+m_website+"\""
  return csv; 
 
/**
 * Check valid DOB 
 * @param dob Date of birth 
 * @return True if valid 
 */
 
 public boolean ValidDob(Calendar dob){ 
  if (dob.equals("")){ 
   System.out.println("Please enter a valid dob " + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /**
  * check valid mobile 
  * @param mobilephone number 
  * @return true if valid 
  */
 
 public boolean ValidMobilephone(String mobilephone){ 
  if (mobilephone.equals("")){ 
   System.out.println("Please enter a valid mobilephone number" + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /**
  * check valid land phone 
  * @param landphone number 
  * @return true if valid 
  */
 
 public boolean ValidLandphone(String landphone){ 
  if (landphone.equals("")){ 
   System.out.println("Please enter a valid landphonenumber " + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /**
  * check valid workphone 
  * @param workphone number 
  * @return true if valid 
  */
 
 public boolean ValidWorkphone(String workphone){ 
  if (workphone.equals("")){ 
   System.out.println("Please enter a valid workphone " + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /**
  * check valid email 
  * @param email email 
  * @return true if valid 
  */
 
 public boolean ValidEmail(String email){ 
  if (email.equals("")){ 
   System.out.println("Please enter a valid email " + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /**
  * check valid work email 
  * @param workemail email 
  * @return true if valid 
  */
 
 public boolean ValidWorkemail(String workemail){ 
  if (workemail.equals("")){ 
   System.out.println("Please enter a valid workemail " + 
     "(1 or more characters)"); 
   return false
  
  return true
 
 
 /*
    public static void main (String[] args){ 
     Contact jama = new Contact(); 
     Contact hammed = new Contact(); 
     jama.SetDob(Calendar.getInstance()); 
     jama.SetId(3252646); 
     jama.SetName("Adam Jama"); 
     jama.SetLandphone("027428928"); 
     jama.SetMobilephone("278489234"); 
     jama.SetWorkphone("3853932"); 
     jama.SetEmail("hello@gmail"); 
     jama.SetWorkemail("bye@gmail"); 
 
     hammed.SetDob(Calendar.getInstance()); 
     hammed.SetId(3252646); 
     hammed.SetName("hammed hammed"); 
     hammed.SetLandphone("027428928643"); 
     hammed.SetMobilephone("278489234637"); 
     hammed.SetWorkphone("38539336542"); 
     hammed.SetEmail("helloand@gmail"); 
     hammed.SetWorkemail("byeand@gmail"); 
 
     System.out.println(jama.GetDob() + " " + jama.GetId() + " " +  
     jama.GetName() + " " + jama.GetLandphone() + " " +  
       jama.GetMobilephone() + " " + jama.GetEmail() + " " +  
     jama.GetWorkemail()); 
 
     System.out.println(hammed.GetDob() + " " + hammed.GetId() + " " + 
     hammed.GetName() + " " + hammed.GetLandphone() + " " +  
       hammed.GetMobilephone() + " " + hammed.GetEmail() + " " +  
     hammed.GetWorkemail()); 
    }*/
 
}