Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.text.DateFormat;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.ArrayList;
  5.  
  6. public class Faculty {
  7. String dob;
  8. String fullName;
  9.  
  10. final static int YEAR_FOUNDED = 1785;
  11.  
  12. public Faculty(){
  13.  
  14. }
  15.  
  16. public Faculty(String name,String dob)
  17. {
  18. fullName = name;
  19. this.dob = dob;
  20.  
  21. }
  22.  
  23. public void setName(String name){
  24. fullName = name;
  25. }
  26.  
  27. public void setDOB (String dob){
  28. this.dob = dob;
  29. }
  30.  
  31. public String createUsername() {
  32.  
  33. ArrayList<Integer> spaces = new ArrayList<Integer>();
  34. String username = "";
  35.  
  36. int ind = 0;
  37.  
  38. // Runs through the full name and records the amount of spaces in it
  39. do {
  40. ind = fullName.indexOf(" ", ind);
  41.  
  42. if(ind != -1)
  43. spaces.add(ind);
  44.  
  45. ind++;
  46.  
  47. } while(ind != 0);
  48.  
  49. String lastName = fullName.substring(spaces.get(spaces.size() - 1) + 1, fullName.length());
  50. String firstInit = fullName.substring(0, 1);
  51.  
  52. username += firstInit;
  53. username += lastName;
  54.  
  55. return username;
  56. }
  57.  
  58. public int getAge(){
  59.  
  60. DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
  61. Date date = new Date();
  62. String dd = dateFormat.format(date);
  63.  
  64. int age = 0;
  65.  
  66. int currentYear = Integer.parseInt(dd.substring(6, dd.length()));
  67. int currentMonth = Integer.parseInt(dd.substring(0, 2));
  68. int currentDay = Integer.parseInt(dd.substring(3, 5));
  69.  
  70. int birthYear = Integer.parseInt(dob.substring(6, dob.length()));
  71. int birthMonth = Integer.parseInt(dob.substring(0, 2));
  72. int birthDay = Integer.parseInt(dob.substring(3, 5));
  73.  
  74. if(currentYear > birthYear && currentMonth >= birthMonth && currentDay >= birthDay) {
  75. age = currentYear - birthYear;
  76. }
  77.  
  78. return age;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement