You are tasked with writing a program called SocialSecurity
You are tasked with writing a program called SocialSecurity that prompts the user to enter the data (name
and date-of-birth)for a collection of people. The program will then process this collection (array) of People
(objects we create in another file) to determine who qualifies for Social Security benefits.
Specifications
For our Social Security program we will need two java files
1. Person.java The person class which stores the data for a specific individual.
2. SocialSecurity.java (The driver)
Details for these two class files appear below.
Person.java UML diagram
Person.java method description
• Two constructors
1. A Default constructor that creates a Person whose name and birthdate are set to null.
2. A parameterized constructor that accepts a String representation of the name, and three integers
corresponding to the month, day, and year in which the person was born.
• Setters and getters for the two instance variables.
• A toString() method that prints the person in the form
<name > : dob - <LocalDate >
• A method called calculateAge which has one parameter, a LocalDate, and returns the age in years
between that date and the current date.
Hints when coding the Person class
• First question: What is a LocalDate?
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
I would pay particular attention to the
of(int ,int , int )
method. It is the one three methods necessary to complete this assignment.
You may need to import the LocalDate class.
• How do I stringify the “LocalDate” object for use in toString()
DateTimeFormatter formatter = DateTimeFormatter . ofPattern (\"MM/dd/yyyy \");
birthdate . format ( formatter )
You may need to import the DateTimeFormatter class.
• calculateAge()
– How do I get the current data?
LocalDate today = LocalDate .now ();
– How do I compute the time between two local dates?
int age = Period . between ( birthDate , today ). getYears ();
You may need to import the Period class.
SocialSecurity- Driver
The SocialSecurity.java file has one method in it – main.
The main method should behave in the following manner:
1. Check for exactly one command line argument.
• If the user supplies more than one number, print an error message
Invalid number of command line arguments .
and exit.
• Otherwise, save this number. This number, which this document refers to as numPeople, refers
to the number of people that we will be processing.
2. Using numPeople construct an array of Person objects.
3. Write a loop construct that does the following for each prospective Person in the array:
• Prompt the user to enter the person’s name. (This will require a scanner object because we are
getting direct input from the user.)
• Prompt the user to enter the person’s date-of-birth in the form <month> space <day> space
<year>
• Create a Person object using the information garnered from the above questions.
4. Lastly, process the array created in step 3 person by person. Print the Person object (implicitly calling
the toString method) stored at the specified array index. Then use the static method in Person.java
to determine if the person qualifies for Social Security.
• If the person’s age is greater than or equal to 66 they qualify for standard Social Security benefits,
otherwise
• They do not qualify for social security benefits
Example Output
java SocialSecurity 4
Enter Person 1’s name : John Doe
Enter Person 1’s Birthday ( month day year ): 11 25 1965
Enter Person 2’s name : Jane Smith
Enter Person 2’s Birthday ( month day year ): 11 07 1950
Enter Person 3’s name : John Hancock
Enter Person 3’s Birthday ( month day year ): 2 24 1985
Enter Person 4’s name : Leto Atreides
Enter Person 4’s Birthday ( month day year ): 7 10 1995
****************************
John Doe: dob - 11/25/1965
Does not qualify for Social Security benefits
Jane Smith : dob - 11/07/1950
Qualifies for standard Social Security benefits
John Hancock : dob - 02/24/1985
Does not qualify for Social Security benefits
Leto Atreides : dob - 07/10/1995
Does not qualify for Social Security benefits
java SocialSecurity 10 2
Invalid number of command line arguments
| Person |
| - name: String - birthdate: LocalDate |
| + Person() + Person(newName: String, month: int, day: int, year: int) + setName(newName: String) : void + getName() : String + setBirthDate(month : int, day : int, year : int) : void + getBirthDate() : LocalDate + toString(): String + calculateAge(myBirth : LocalDate) : int |
Solution
class Preson{
public Person() {
name =\"YetToBeNamed\";
birtgdayyear =1999;//my default
}
public Preson(String giveName, int yearofbirth) {
name = giveName;
birthdayYear = yearogBrith;
}
public String getName() {\"
return name;
}
public String changeName(String name) {
String aux;
aux =this.name;
this.name = name;
return aux;
}
public int getAgeInYear) {
return currenYear-birthdayYear;
}
private String name;
private int birthdayYear;
public static void main(String[] args) {
Person a=new Preson();
Preson b=new Preson(\"Richard P. Feynman\",1918);
String name=a.changeName(\"The Next Richard Feynman\");
System.out.println(\"Physicist\"+name+\"makes big\"+\"discovery,touted as\"+a.getName());
System.out.println(b.getName()+\"was\"+b.getAgeInYears(1945)+\"in 1945, in May.\");
}
}


