binibiningtinamoran

Event.java

Nov 25th, 2020 (edited)
594
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Event {
  2.  
  3.     public final double PRICE_PER_PERSON = 35.00; // Price per guest - Lg Party
  4.     public final double DISCOUNT_PRICE = 32.00; // Price per guest - Sm Party
  5.     public final int LG_PARTY = 50; // Minimum Lg Party Qty
  6.     public final int EVENT_NUM_LENGTH = 4; // Event number length
  7.  
  8.     // Event type
  9.     public final static String[] EVENT_TYPES = { "Wedding", "Baptism", "Birthday", "Corporate", "Other" };
  10.  
  11.     private String eventNum;
  12.     private int numOfGuests;
  13.     private double pricePerGuest;
  14.     private String phoneNumber;
  15.     private int eventType;
  16.  
  17.     public Event(String eventNum, int numOfGuests, String phoneNumber, int eventType) {
  18.         setEventNum(eventNum);
  19.         setNumOfGuests(numOfGuests);
  20.         setPhoneNumber(phoneNumber);
  21.         setEventType(eventType);
  22.     }
  23.  
  24.     // Default input information
  25.     public Event() {
  26.         this("A000", 0, "0000000000", EVENT_TYPES.length - 1);
  27.     }
  28.  
  29.     // Format Event Number or revert to default
  30.     public void setEventNum(String eventNum) {
  31.         if (eventNum.length() != EVENT_NUM_LENGTH || !Character.isLetter(eventNum.charAt(0))
  32.                 || !Character.isDigit(eventNum.charAt(1)) || !Character.isDigit(eventNum.charAt(2))
  33.                 || !Character.isDigit(eventNum.charAt(3))) {
  34.             this.eventNum = "A000";
  35.         } else {
  36.             this.eventNum = eventNum.toUpperCase();
  37.         }
  38.     }
  39.  
  40.     // Calculate price based on Number of Guests <---WHY ???
  41.     public void setNumOfGuests(int numOfGuests) {
  42.         this.numOfGuests = numOfGuests;
  43.     }
  44.  
  45.     // Format Phone Number or revert to default
  46.     public void setPhoneNumber(String phone) {
  47.         final int VALID_PHONE = 10;
  48.         final String INVALID_PHONE = "0000000000";
  49.         phoneNumber = "";
  50.         int len = phone.length();
  51.         for (int x = 0; x < len; ++x) {
  52.             if (Character.isDigit(phone.charAt(x))) {
  53.                 phoneNumber += phone.charAt(x);
  54.             }
  55.         }
  56.         if (phoneNumber.length() != VALID_PHONE) {
  57.             phoneNumber = INVALID_PHONE;
  58.         }
  59.     }
  60.  
  61.     // Set event type
  62.     public void setEventType(int eventType) {
  63.         if (eventType < EVENT_TYPES.length) {
  64.             this.eventType = eventType;
  65.         } else {
  66.             this.eventType = EVENT_TYPES.length - 1;
  67.         }
  68.     }
  69.  
  70.     // Get phone number input from user
  71.     public String getPhoneNumber() {
  72.         String phone;
  73.         phone = "(" + phoneNumber.substring(0, 3) + ") " + phoneNumber.substring(3, 6) + "-"
  74.                 + phoneNumber.substring(6, 10);
  75.         return phone;
  76.     }
  77.  
  78.     public String getEventNum() {
  79.         return eventNum;
  80.     }
  81.  
  82.     public int getNumOfGuests() {
  83.         return numOfGuests;
  84.     }
  85.  
  86.     public void setPricePerGuest(double pricePerGuest) {
  87.         if (isLargeEvent()) {
  88.             this.pricePerGuest = DISCOUNT_PRICE;
  89.         } else {
  90.             this.pricePerGuest = PRICE_PER_PERSON;
  91.         }
  92.     }
  93.  
  94.     public double getPricePerGuest() {
  95.         return pricePerGuest;
  96.     }
  97.     public int getEventType() {
  98.         return eventType;
  99.     }
  100.  
  101.     public String getEventTypeSelect() {
  102.         return EVENT_TYPES[eventType];
  103.     }
  104.  
  105.     public boolean isLargeEvent() {
  106.         return numOfGuests >= 50;
  107.     }
  108.  
  109.     public double getTotalPrice() {
  110.  
  111.         double total;
  112.         // Calculate total for party size
  113.         if (isLargeEvent()) {
  114.             total = this.numOfGuests * DISCOUNT_PRICE;
  115.         } else {
  116.             total = this.numOfGuests * PRICE_PER_PERSON;
  117.         }
  118.         return total;
  119.     }
  120.  
  121. }
RAW Paste Data