In your Person class:
Add a constant field to store the current year (review the Week 4 Lesson if you aren\'t sure how
to create a constant) :
Assign a value to the current year field when it is declared (do not add it to the constructors).
Add fields to store a person\'s age in years and how many years they have been with the college:
Do not add mutator or accessor methods for these fields.
Set the visibility modifier to private for these fields.
Modify both constructors to set default values for both fields.
Add processing actions:
Add a method to calculate a person\'s age in years only.
Add a method to calculate how long a person has been in college in years only.
Make both methods private.
Do not take any input or display any output in these methods.
Modify the toString() method:
Call the method to calculate the person\'s age.
Call the method to calculate how long the person has been in college.
Add the person\'s age to the String.
Add the person\'s time in college to the String.
Add output messages for each field so that 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.
*** This is what I have so far
48 class Persons_Information
49 {
50 private String personName;
51 private String currentAdress;
52 private String permanentAdress;
53 private int idNumber;
54 private String birthDate;
55 private int personAge;
56 private int entryYear;
57 private int totalYears;
58
59 public Persons_Information() {
60 personName = \"\";
61 currentAdress = \"\";
62 permanentAdress = \"\";
63 idNumber = 0;
64 birthDate = \"\";
65 personAge = 0;
66 entryYear = 0;
67 totalYears = 0;
68 }
69
70 public Persons_Information (int atIdNumber) {
71 idNumber = atIdNumber;
72 personName = \"\";
73 currentAdress = \"\";
74 permanentAdress = \"\";
75 birthDate = \"\";
76 personAge = 0;
77 entryYear = 0;
78 totalYears = 0;
79 }
80
81 //intput
82
83 public void setPersonName(String personName) {
84 this.personName = personName;
85 }
86
87 public void setCurrentAdress(String currentAdress) {
88 this.currentAdress = currentAdress;
89 }
90
91
92 public void setpermanentAdress(String permanentAdress) {
93 this.permanentAdress = permanentAdress;
94 }
95
96 public void setIdNumber(int id) {
97 idNumber = id;
98 }
99
100 public void setBirthDate(String birthDate) {
101 this.birthDate = birthDate;
102 }
103
104 public void setPersonAge(int pa) {
105 personAge = pa;
106 }
107
108 public void setEntryYear(int ey) {
109 entryYear = ey;
110 }
111
112 public void setTotalYears(int ty) {
113 totalYears = ty;
114 }
115
116 //output
117
118 public String getPersonName() {
119 return personName;
120 }
121
122 public String getCurrentAdress() {
123 return currentAdress;
124 }
125
126 public String getPermanentAdress() {
127 return permanentAdress;
128 }
129
130 public int getIdNumber() {
131 return idNumber;
132 }
133 public String getBirthDate() {
134 return birthDate;
135 }
136
137 pu.
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
In your Person classAdd a constant field to store the current yea.pdf
1. In your Person class:
Add a constant field to store the current year (review the Week 4 Lesson if you aren't sure how
to create a constant) :
Assign a value to the current year field when it is declared (do not add it to the constructors).
Add fields to store a person's age in years and how many years they have been with the college:
Do not add mutator or accessor methods for these fields.
Set the visibility modifier to private for these fields.
Modify both constructors to set default values for both fields.
Add processing actions:
Add a method to calculate a person's age in years only.
Add a method to calculate how long a person has been in college in years only.
Make both methods private.
Do not take any input or display any output in these methods.
Modify the toString() method:
Call the method to calculate the person's age.
Call the method to calculate how long the person has been in college.
Add the person's age to the String.
Add the person's time in college to the String.
Add output messages for each field so that 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.
*** This is what I have so far
48 class Persons_Information
49 {
50 private String personName;
51 private String currentAdress;
52 private String permanentAdress;
53 private int idNumber;
54 private String birthDate;
55 private int personAge;
56 private int entryYear;
57 private int totalYears;
58
59 public Persons_Information() {
60 personName = "";
11. return entryYear;
}
publicint getTotalYears() {
return totalYears;
}
//Method To Calculate Age of a person
privateint calculatePersonAge() {
//CALCULATE THE CURRENT YEAR, MONTH AND DAY
//INTO SEPERATE VARIABLES
int yearDOB = Integer.parseInt(birthDate.substring(0, 4));
DateFormat dateFormat = new SimpleDateFormat("YYYY");
java.util.Date date = new java.util.Date();
int thisYear = Integer.parseInt(dateFormat.format(date));
dateFormat = new SimpleDateFormat("MM");
date = new java.util.Date();
intthisMonth = Integer.parseInt(dateFormat.format(date));
dateFormat = new SimpleDateFormat("DD");
date = new java.util.Date();
intthisDay = Integer.parseInt(dateFormat.format(date));
//CREATE AN AGE VARIABLE TO HOLD THE CALCULATED AGE
//TO START WILL – SET THE AGE EQUEL TO THE CURRENT YEAR MINUS THE
YEAR
//OF THE DOB
int age = thisYear-yearDOB;
return age;
}
//Method To Calculate Duration of person in college
privateint durationInCollege() {
//CALCULATE THE CURRENT YEAR
//INTO SEPERATE VARIABLES
DateFormat dateFormat = new SimpleDateFormat("YYYY");
java.util.Date date = new java.util.Date();
int thisYear = Integer.parseInt(dateFormat.format(date));
//CREATE AN AGE VARIABLE TO HOLD THE CALCULATED AGE
//To Calculate Duration we will subtract current year from entry year
int totalYears = thisYear-entryYear;
12. return totalYears;
}
//toString
public String toString()
{
return " Name:" + personName +
" Current Adress:" + currentAdress +
" Permanent Adress:" + permanentAdress +
" ID Number:" + idNumber +
" Birth Date" + birthDate +
" Age:" + calculatePersonAge() +
" Entry Year:" + entryYear +
" Total Years in System:" + durationInCollege();
}
}