Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author Mason Cudlitz
  4.  */
  5. public class DataBaseValue {
  6.  
  7.     Calendar calendar;
  8.     Date createdDate;
  9.     private final String name;
  10.  
  11.     public DataBaseValue(String name) {
  12.         this.name = name;
  13.         calendar = Calendar.getInstance();
  14.         createdDate = calendar.getTime();
  15.     }
  16.  
  17.     public String getName() {
  18.         return name;
  19.     }
  20.  
  21.     //overridden
  22.     public String getInfo() {
  23.         return "I AM ERROR";
  24.     }
  25.  
  26.     public Date getCreatedDate() {
  27.         return createdDate;
  28.     }
  29. }
  30.  
  31. class International extends DataBaseValue {
  32.  
  33.     //Fields
  34.     private final int id;
  35.     private final Date dateOfBirth;
  36.     private final String homeAddress;
  37.     private final String localAddress;
  38.     private final String phoneNumber;
  39.     private int age;
  40.     private final Visa visa;
  41.  
  42.     //input
  43.     Scanner input = new Scanner(System.in);
  44.  
  45.     International(String name, Date dateOfBirth, String homeAddress,
  46.             String localAddress, String phoneNumber, Visa visa) {
  47.         super(name);
  48.         this.id = name.hashCode();
  49.         this.dateOfBirth = dateOfBirth;
  50.         setAge(dateOfBirth);
  51.         this.homeAddress = homeAddress;
  52.         this.localAddress = localAddress;
  53.         this.phoneNumber = phoneNumber;
  54.         this.visa = visa;
  55.  
  56.     }
  57.  
  58.     void setAge(Date dateOfBirth) {
  59.         age = (int) (TimeUnit.DAYS.convert(StaticDataFunctions.deltaTime(dateOfBirth, getCreatedDate()), TimeUnit.MILLISECONDS) / 365);
  60.     }
  61.  
  62.     //Accessors
  63.     public Visa getVisa() {
  64.         return visa;
  65.     }
  66.  
  67.     public int getAge() {
  68.         return age;
  69.     }
  70.  
  71.     //Builds a return card for the person when retrieved from the Database
  72.     String formatInfo(String[] extraParameters) {
  73.         String[] infoLines = new String[]{
  74.             "Name: " + this.getName(),
  75.             "Date of Birth: " + dateOfBirth.getMonth() + "/" + dateOfBirth.getDay() + "/" + dateOfBirth.getYear(),
  76.             "Age: " + age + " years",
  77.             "Home Address: " + homeAddress,
  78.             "Local Address: " + localAddress,
  79.             "Visa class: " + visa.getVisaType(),
  80.             "Visa permissions: " + visa.getVisaPermissions(),
  81.             "Expiry date: " + visa.getExpiryDate() + " (expires in " + visa.getExpiryDays() + " days)"
  82.         };
  83.  
  84.         if (extraParameters != null) {
  85.             infoLines = (String[]) StaticDataFunctions.concatenateArrays(infoLines, extraParameters);
  86.         }
  87.  
  88.         int longestLine = 0;
  89.         for (String l : infoLines) {
  90.             if (l.length() > longestLine) {
  91.                 longestLine = l.length() + 2;
  92.             }
  93.         }
  94.  
  95.         StringBuilder formatBuilder = new StringBuilder();
  96.         for (int y = 0; y < infoLines.length + 2; y++) {
  97.             formatBuilder.append('\n');
  98.             for (int x = 0; x < longestLine; x++) {
  99.                 //Draws box
  100.                 if (y == 0 || y == infoLines.length + 1 || x == longestLine - 1) {
  101.                     formatBuilder.append('/');
  102.                 } else if (x == 0) {
  103.                     if (y > 0 && y < infoLines.length + 1) {
  104.                         formatBuilder.append('/').append(infoLines[y - 1]);
  105.                         x += infoLines[y - 1].length();
  106.                         //x -= infoLines[y - 1].length();
  107.                     }
  108.                 } else {
  109.                     formatBuilder.append(" ");
  110.                 }
  111.  
  112.             }
  113.  
  114.         }
  115.         return formatBuilder.toString();
  116.     }
  117.  
  118.     //This will be overriden
  119. }
  120.  
  121. class Intellectual extends International {
  122.     List<Class> classes = new ArrayList();
  123.    
  124.     public Intellectual(String name, Date dateOfBirth, String homeAddress, String localAddress,
  125.             String phoneNumber, Visa visa) {
  126.         super(name, dateOfBirth, homeAddress, localAddress, phoneNumber, visa);
  127.     }
  128.  
  129.     public String addClass(Class newClass) {
  130.         //Overridden
  131.         return "Err";
  132.     }
  133.  
  134.     public String removeClass(Class removedClass) {
  135.         //Overridden
  136.         return "Err";
  137.     }
  138.    
  139.     public boolean hasClass(Class checkedClass){
  140.         return classes.contains(checkedClass);
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement