Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.ArrayList;
- public class Faculty {
- String dob;
- String fullName;
- final static int YEAR_FOUNDED = 1785;
- public Faculty(){
- }
- public Faculty(String name,String dob)
- {
- fullName = name;
- this.dob = dob;
- }
- public void setName(String name){
- fullName = name;
- }
- public void setDOB (String dob){
- this.dob = dob;
- }
- public String createUsername() {
- ArrayList<Integer> spaces = new ArrayList<Integer>();
- String username = "";
- int ind = 0;
- // Runs through the full name and records the amount of spaces in it
- do {
- ind = fullName.indexOf(" ", ind);
- if(ind != -1)
- spaces.add(ind);
- ind++;
- } while(ind != 0);
- String lastName = fullName.substring(spaces.get(spaces.size() - 1) + 1, fullName.length());
- String firstInit = fullName.substring(0, 1);
- username += firstInit;
- username += lastName;
- return username;
- }
- public int getAge(){
- DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
- Date date = new Date();
- String dd = dateFormat.format(date);
- int age = 0;
- int currentYear = Integer.parseInt(dd.substring(6, dd.length()));
- int currentMonth = Integer.parseInt(dd.substring(0, 2));
- int currentDay = Integer.parseInt(dd.substring(3, 5));
- int birthYear = Integer.parseInt(dob.substring(6, dob.length()));
- int birthMonth = Integer.parseInt(dob.substring(0, 2));
- int birthDay = Integer.parseInt(dob.substring(3, 5));
- if(currentYear > birthYear && currentMonth >= birthMonth && currentDay >= birthDay) {
- age = currentYear - birthYear;
- }
- return age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement