I need help making these adjustments to my class PersonsInfo

I need help making these adjustments to my \"class Persons_Information\"

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 public int getPersonAge() {
138 return personAge;
139 }
140
141 public int getEntryYear() {
142 return entryYear;
143 }
144
145 public int getTotalYears() {
146 return totalYears;
147 }
148
149 //toString
150
151 public String toString()
152 {
153 return \"\ \ Name:\" + personName +
154 \"\ Current Adress:\" + currentAdress +
155 \"\ Permanent Adress:\" + permanentAdress +
156 \"\ ID Number:\" + idNumber +
157 \"\ Birth Date\" + birthDate +
158 \"\ Age:\" + personAge +
159 \"\ Entry Year:\" + entryYear +
160 \"\ Total Years in System:\" + totalYears;
161 }
162 }
163

Solution

solution

package com.prt.test;

import java.text.ParseException;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

class Persons_Information

{
   public static final int CURRENT_YEAR = 2016;
   private String personName;
   private String currentAdress;
   private String permanentAdress;
   private int idNumber;
   private String birthDate;
   private int personAge;
   private int entryYear;
   private int totalYears;
   private int yearsinCollege;

   public Persons_Information() {
       personName = \"\";
       currentAdress = \"\";
       permanentAdress = \"\";
       idNumber = 0;
       birthDate = \"\";
       personAge = 0;
       entryYear = 0;
       totalYears = 0;
       yearsinCollege = 0;
   }

   /**
   * @param permanentAdress
   * the permanentAdress to set
   */
   public void setPermanentAdress(String permanentAdress) {
       this.permanentAdress = permanentAdress;
   }

   public Persons_Information(int atIdNumber) {
       idNumber = atIdNumber;
       personName = \"\";
       currentAdress = \"\";
       permanentAdress = \"\";
       birthDate = \"\";
       personAge = 0;
       entryYear = 0;
       totalYears = 0;
       yearsinCollege = 0;
   }

   // intput

   public void setPersonName(String personName) {
       this.personName = personName;
   }

   public void setCurrentAdress(String currentAdress) {
       this.currentAdress = currentAdress;
   }

   public void setpermanentAdress(String permanentAdress) {
       this.permanentAdress = permanentAdress;
   }

   public void setIdNumber(int id) {
       idNumber = id;
   }

   public void setBirthDate(String birthDate) {
       this.birthDate = birthDate;
   }

   public void setPersonAge(int pa) {
       personAge = pa;
   }

   public void setEntryYear(int ey) {
       entryYear = ey;
   }

   public void setTotalYears(int ty) {
       totalYears = ty;
   }

   // output

   public String getPersonName() {
       return personName;
   }

   public String getCurrentAdress() {
       return currentAdress;
   }

   public String getPermanentAdress() {
       return permanentAdress;
   }

   public int getIdNumber() {
       return idNumber;
   }

   public String getBirthDate() {
       return birthDate;
   }

   public int getPersonAge() {
       return personAge;
   }

   public int getEntryYear() {
       return entryYear;
   }

   public int getTotalYears() {
       return totalYears;
   }

   // toString

   public String toString() {
       return \"\ \ Name:\" + personName + \"\ Current Adress:\" + currentAdress
               + \"\ Permanent Adress:\" + permanentAdress + \"\ ID Number:\"
               + idNumber + \"\ Birth Date\" + birthDate + \"\ Age:\"
               + personAge + \"\ Entry Year:\" + entryYear
               + \"\ Total Years in System:\" + totalYears;
   }

   private void calculatePersonAge() {
       //initialization
       int noofyears = 0;
       Date convertedbirthdaydate, convertedCurrentdate = null;
      
       Persons_Information in=new Persons_Information();
       Date todaysDate = new Date();
       Scanner scanner = new Scanner(System.in);

       SimpleDateFormat format = new SimpleDateFormat(\"yyyy-MM-dd\");

       String currentdate = format.format(todaysDate);//to change current date in string

       System.out
               .println(\"enter your birthdate in only this format dd-mm-yyyy\");
       String birthdate = scanner.next();
       String dateFormat1 = \"dd-MM-yyyy\";

       String curdate = currentdate;
       String dateFormat2 = \"yyyy-MM-dd\";

       SimpleDateFormat format1 = new SimpleDateFormat(dateFormat1);
       SimpleDateFormat format2 = new SimpleDateFormat(dateFormat2);
       SimpleDateFormat Year = new SimpleDateFormat(\"yyyy\");//to change the year format

       try {
           convertedbirthdaydate = (Date) format1.parse(birthdate);
           convertedCurrentdate = (Date) format2.parse(curdate);

           int year1 = Integer.parseInt(Year.format(convertedbirthdaydate));
           // int year2 = Integer.parseInt(Year.format(convertedCurrentdate));
           int year2 = CURRENT_YEAR;
           noofyears = year2 - year1;
       } catch (ParseException ex) {
           System.out.println(\"invalid date format enter given format\");
           calculatePersonAge();
       }
       System.out.println(\"no of years\" + noofyears);

   }

   private void getYearsInCollege()

   {
       Persons_Information in = new Persons_Information();
      
       Scanner scanner=new Scanner(System.in);
      
System.out.println(\"enter entry year in your college \");
  
in.setEntryYear(scanner.nextInt());
  
       int years = CURRENT_YEAR - (in.getEntryYear());
      
       System.out.println(\"no of years in college\" + years);

   }

   public static void main(String[] args) {

       Persons_Information in = new Persons_Information();

       in.calculatePersonAge();
       in.getYearsInCollege();
   }

}

output

enter your birthdate in only this format dd-mm-yyyy
02-06-1988
no of years28
enter entry year in your college
2010
no of years in college6

I need help making these adjustments to my \
I need help making these adjustments to my \
I need help making these adjustments to my \
I need help making these adjustments to my \
I need help making these adjustments to my \
I need help making these adjustments to my \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site