Design a class which stores demographic information of a per
Design a class which stores demographic information of a person like name, address, phone number, male/female. What if the person has any prefix to the name, multiple phone numbers/addresses, how will you handle dob in case of multiple locations(If a person is both at 12 PM in USA on a date, then that date is different from date in India), how will you handle the validations of these fields when the user enters the values.
Solution
This will be the program for the above scenario and please let me know if any errors occurs.
public class Person
{
private String name;
private String address;
private String phoneNumber;
private String gender;
public Person(String name, String address, String phoneNumber, String gender) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.gender = gender;
}
public String toString()
{
return \"Person{\" + \"name=\" + name + \", address=\" + address + \", phoneNumber=\" + phoneNumber + \", \"+ \"gender=\" + gender + \'}\';
}
public void disp()
{
System.out.println(\"gender = \"+gender+\"Name= \"+name +\"address= \"+address +\"phoneNumber= \"+phoneNumber);
}
}
package demographic;
import java.util.Scanner;
public class PersonDriver
{
public static void main(String args[])
{
System.out.println(\"Enter your gender\");
Scanner s = new Scanner(System.in);
String gender = s.nextLine();
System.out.println(\"Enter name\");
String name = s.nextLine();
System.out.println(\"Enter address\");
String address = s.nextLine();
System.out.println(\"Enter number\");
String phoneNumber = s.nextLine();
Person p = new Person(name,address,phoneNumber,gender);
p.disp();
}
}

