Create a refernce data type using the following criteria Mak
Create a refernce data type using the following criteria. Make sure the class and test class compile corrrectly.
Problem statement:
 Create a reference data type that will be used by a college to store a persons
 information. The information that needs to be stored are the persons name,
 current address, permanent address, id number, date of birth, current age, year
 the person entered the college system, and how long the person has been with
 the college. Rather than ask for the current age, calculate it using the persons
 date of birth and current year. Rather than ask for how long the user has been with
 the college, calculate it using by using the year the person first entered the system
 and the current year.
(Part A. )In your Person class:
Add mutator methods for each field.
Do not use Scanner in the Person class.
All values will be passed in via parameters.
Add accessor methods for each field.
Add a toString() method.
Include all fields.
Include a message with each field so the user knows what they are looking at.
Format the string using the new line escape sequence \ so that each field and it\'s message is on a separate line.
(Part B.) In your test class:For the first object:
Use Scanner to collect values for each field from the user.
Include a prompt with each input telling the user what the input is for.
Call the appropriate mutator function to set the value.
Call the appropriate accessor function to display the value.
After all input has been collected, call the toString() method to display all of the values.
For the second object:
Use Scanner to collect values for each field from the user except id number. The id number should be set in the constructor.
Include a prompt with each input telling the user what the input is for.
Call the appropriate mutator function to set the value.
Call the appropriate accessor function to display the value.
After all input has been collected, call the toString() method to display all of the values.
Make sure it will compile and execute.
Solution
import java.util.*;
 import java.lang.*;
 import java.io.*;
class Person
 {
    private String name;
    private String currentAddress;
    private String permanentAddress;
    private int idNumber;
    private String DOB;
    private int currentYear;
    private int yearEntered;
   
    public Person() //default constructor
    {
       
    }
    public Person(int id) //constructor with id
    {
        idNumber =id;
    }
   
    public void setName(String n) //get and set methods
    {
        name = n;
    }
    public String getName()
    {
        return name;
    }
    public void setCurrentAddress(String ca)
    {
        currentAddress = ca;
    }
    public String getCurrentAddress()
    {
        return currentAddress;
    }
    public void setPermanentAddress(String pa)
    {
        permanentAddress=pa;
    }
    public String getPermanentAddress()
    {
        return permanentAddress;
    }
    public void setIDNumber(int id)
    {
        idNumber =id;
    }
    public int getIDNumber()
    {
        return idNumber;
    }
    public void setDOB(String dob)
    {
        DOB = dob;
    }
    public String getDOB()
    {
        return DOB;
    }
    public void setCurrentYear(int cy)
    {
        currentYear = cy;
    }
    public int getCurrentYear()
    {
        return currentYear;
    }
    public void setYearEntered(int ye)
    {
        yearEntered = ye;
    }
    public int getYearEntered()
    {
        return yearEntered;
    }
    public String toString() //toString() method
    {
        return \"\ Name:\"+ name + \"\ Current Address :\"+ currentAddress +\"\ Permanent Address :\"+ permanentAddress +\"\ ID Number:\"+ idNumber +\"\ Date of Birth:\"+ DOB+\"\ Current Year :\"+ currentYear+\"\ Year Entered in College:\"+ yearEntered;
    }
 }
class PersonTest
 {
    public static void main (String[] args) throws java.lang.Exception
    {
        Person person1 = new Person(); //person 1
       
        Scanner stdin = new Scanner(System.in);
       
        String name = stdin.next();
        String ca= stdin.next();
        String pa =stdin.next();
        int id = stdin.nextInt();
        String dob = stdin.next();
        int cy = stdin.nextInt();
        int ye =stdin.nextInt();
       
        person1.setName(name);
       
       
        person1.setCurrentAddress(ca);
       
   
        person1.setPermanentAddress(pa);
       
       
        person1.setIDNumber(id);
       
       
        person1.setDOB(dob);
       
       
        person1.setCurrentYear(cy);
       
   
        person1.setYearEntered(ye);
       
    System.out.println(person1.getName());
        System.out.println(person1.getCurrentAddress());
        System.out.println(person1.getPermanentAddress());
        System.out.println(person1.getIDNumber());
        System.out.println(person1.getDOB());
        System.out.println(person1.getCurrentYear());
        System.out.println(person1.getYearEntered());
       
        System.out.println(person1.toString());
        int birthyear = Integer.parseInt(person1.getDOB().substring(6));
        System.out.println(\"birthyear=\"+birthyear);
        int age = person1.getCurrentYear() - birthyear; //calculate age of person
        System.out.println(\"The age of the person is \"+age);
        int duration = person1.getCurrentYear() - person1.getYearEntered();
        System.out.println(\"The person is in the college for \"+duration +\" years\"); //calculate years of person in college
       
        Person person2 = new Person(67879);
       
       
        name = stdin.next();
        ca= stdin.next();
        pa =stdin.next();
        dob = stdin.next();
        cy = stdin.nextInt();
        ye =stdin.nextInt();
       
        person2.setName(name);
       
       
        person2.setCurrentAddress(ca);
       
   
        person2.setPermanentAddress(pa);
       
       
        person2.setDOB(dob);
       
       
        person2.setCurrentYear(cy);
       
   
        person2.setYearEntered(ye);
       
    System.out.println(person2.getName());
        System.out.println(person2.getCurrentAddress());
        System.out.println(person2.getPermanentAddress());
        System.out.println(person2.getIDNumber());
        System.out.println(person2.getDOB());
        System.out.println(person2.getCurrentYear());
        System.out.println(person2.getYearEntered());
       
        System.out.println(person2.toString());
       
    birthyear = Integer.parseInt(person2.getDOB().substring(6));
        System.out.println(\"birthyear=\"+birthyear);
        age = person2.getCurrentYear() - birthyear;
        System.out.println(\"The age of the person is \"+age);
        duration = person2.getCurrentYear() - person2.getYearEntered();
        System.out.println(\"The person is in the college for \"+duration +\" years\");
       
       
    }
 }
output:
Success time: 0.06 memory: 711680 signal:0




