Assignment 2 - Get Classey
Table of contents
Lab Goals:
- Practice creating classes and instantiating objects.
- Instantiate object using data from a text file.
- Persist Object data to a text file.
- Store and Manipulate class objects with an
ArrayList
Final Result:
You will be submitting a git repository with the following naming convention, 2-get-classy-<your-github-username>, (i.e., 2-get-classy-Ygilany). The repository contains:
- one Java Project with the following files:
- Person.java (a class to represent a person object)
- PersonGenerator.java (has a main method)
- PersonReader.java (has a main method)
- SafeInput.java (The source file is available with the assignment instructions)
- The output text file from the PersonGenerator program.
- a modified README.md file that includes your self-assessment
Part 1: Person Generator:
- Create a
Person.javaclass to represent a Person Object.
| Person | ||
|---|---|---|
| Fields | ||
String ID; | ||
String firstName; | ||
String lastName; | ||
String title; | Mr., Mrs., Ms., Prof., Dr., Hon., … | |
int YOB; | - Year of Birth - Range should be 1900-2010 - make sure validations happen in the constructor as well as the setter method. | |
| Methods | ||
| Constructor | ||
| Getters and Setters | ||
public String fullName() | returns a concatenation of the first and last names | |
public String formalName() | returns a concatenation of the title and the full name | |
public static int getAge(int year) | - A static method that takes a year and returns an age. - Use the Calendar Object to get current Year (may requires a bit of web search) | |
public String toCSVDataRecord() | - returns a comma separated value (csv) String suitable to writing to a java text file. - Make sure to use this function when saving data to the file. - (i.e., 0001,John, Doe,Mr., 2000) |
- Create a program (Java main class) called
PersonGenerator.java.- a user will input the data to the console.
- a Person object is created for each entry.
- Store all the Person objects in an
ArrayList<Person> - Export all the Person objects to a text file using the
toCSVDataRecord()method
Grading
- The program runs with no errors.
- The Person class includes all the fields and methods specified above.
- Usage of the
Calendarobject to calculate age in thegetAgemethod. - The program properly instantiates objects using the class constructor.
- The program properly stores the Objects in an
ArrayList. - Proper usage of Git and GitHub (frequent commits, explanatory commit messages)
Part2: Person Reader
- Create a program (Java main class) called
PersonReader.java.- Use the
JFileChooserto prompt the user to select the file you export in Part 1. - Instantiate a Person Object for each record you read from the file.
- Store all the Person Objects in an
ArrayList<Person>. - Use the
String.formatorSystem.out.printfmethod to create a neatly formatted columnar display of the data.
- Use the
ID Firstname Lastname Title YOB
==================================================
0001 John Doe Mr. 1990
0002 Jane Doe Mrs. 1993
Grading
- The program runs with no errors.
- The program properly uses the
JFileChooser. - The program properly instantiates objects using the class constructor.
- The program properly stores the Objects in an
ArrayList. - The program output is formatted properly.
- Proper usage of Git and GitHub (frequent commits, explanatory commit messages)