Advertisement
Guest User

RentalAppt

a guest
Nov 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. //RentalAppt
  2.  
  3. class RentalAppt extends LessonWithRental
  4.  
  5. {
  6.  
  7. public static final int MINUTES_IN_HOUR = 60;
  8.  
  9. public static final int HOUR_RATE = 40;
  10.  
  11. public static final int CONTRACT_NUM_LENGTH = 4;
  12.  
  13. public static final String[] EQUIP_TYPES =
  14.  
  15. {"personal watercraft", "pontoon boat", "rowboat", "canoe", "kayak",
  16.  
  17. "beach chair", "umbrella", "other"};
  18.  
  19. private String contractNumber;
  20.  
  21. private int hours;
  22.  
  23. private int extraMinutes;
  24.  
  25. private double price;
  26.  
  27. private String contactPhone;
  28.  
  29. private int equipType;
  30.  
  31. public RentalAppt(String num, int minutes)
  32.  
  33. {
  34.  
  35. setContractNumber(num);
  36.  
  37. setHoursAndMinutes(minutes);
  38.  
  39. }
  40.  
  41. public RentalAppt()
  42.  
  43. {
  44.  
  45. this("A000", 0);
  46.  
  47. }
  48.  
  49. public void setContractNumber(String num)
  50.  
  51. {
  52.  
  53. boolean numOk = true;
  54.  
  55. if(num.length() != CONTRACT_NUM_LENGTH ||
  56.  
  57. !Character.isLetter(num.charAt(0)) ||
  58.  
  59. !Character.isDigit(num.charAt(1)) ||
  60.  
  61. !Character.isDigit(num.charAt(2)) ||
  62.  
  63. !Character.isDigit(num.charAt(3)))
  64.  
  65. contractNumber = "A000";      
  66.  
  67. else
  68.  
  69. contractNumber = num.toUpperCase();
  70.  
  71. }
  72.  
  73. public void setHoursAndMinutes(int minutes)
  74.  
  75. {
  76.  
  77. hours = minutes / MINUTES_IN_HOUR;
  78.  
  79. extraMinutes = minutes % MINUTES_IN_HOUR;
  80.  
  81. if(extraMinutes <= HOUR_RATE)
  82.  
  83. price = hours * HOUR_RATE + extraMinutes;
  84.  
  85. else
  86.  
  87. price = hours * HOUR_RATE + HOUR_RATE;
  88.  
  89. }
  90.  
  91. public String getContractNumber()
  92.  
  93. {
  94.  
  95. return contractNumber;
  96.  
  97. }
  98.  
  99. public int getHours()
  100.  
  101. {
  102.  
  103. return hours;
  104.  
  105. }
  106.  
  107. public int getExtraMinutes()
  108.  
  109. {
  110.  
  111. return extraMinutes;
  112.  
  113. }
  114.  
  115. public double getPrice()
  116.  
  117. {
  118.  
  119. return price;
  120.  
  121. }
  122.  
  123. public String getContactPhone()
  124.  
  125. {
  126.  
  127. String phone;
  128.  
  129. phone = "(" + contactPhone.substring(0, 3) + ") " +
  130.  
  131. contactPhone.substring(3, 6) + "-" +
  132.  
  133. contactPhone.substring(6, 10);
  134.  
  135. return phone;
  136.  
  137. }
  138.  
  139. public void setContactPhone(String phone)
  140.  
  141. {
  142.  
  143. final int VALID_LEN = 10;
  144.  
  145. final String INVALID_PHONE = "0000000000";
  146.  
  147. contactPhone = "";
  148.  
  149. int len = phone.length();
  150.  
  151. for(int x = 0; x < len; ++x)
  152.  
  153. {
  154.  
  155. if(Character.isDigit(phone.charAt(x)))
  156.  
  157. contactPhone += phone.charAt(x);
  158.  
  159. }
  160.  
  161. if(contactPhone.length() != VALID_LEN)
  162.  
  163. contactPhone = INVALID_PHONE;
  164.  
  165. }
  166.  
  167. public void setEquipType(int eType)
  168.  
  169. {
  170.  
  171. if(eType < EQUIP_TYPES.length)
  172.  
  173. equipType = eType;
  174.  
  175. else
  176.  
  177. equipType = EQUIP_TYPES.length - 1;
  178.  
  179. }
  180.  
  181. public int getEquipType()
  182.  
  183. {
  184.  
  185. return equipType;
  186.  
  187. }
  188.  
  189. public String getEquipTypeString()
  190.  
  191. {
  192.  
  193. return EQUIP_TYPES[equipType];
  194.  
  195. }           
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement