Guest User

Untitled

a guest
Jan 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.56 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. "use strict";
  12.  
  13. // this is some practice with "classes" in JS
  14.  
  15. // create my 'parent class'
  16. class Store {
  17. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits) {
  18. this._storeName = storeName;
  19. this._locationNumber = locationNumber;
  20. this._additionalWaterUnits = additionalWaterUnits;
  21. this._additionalElectricityUnits = additionalElectricityUnits;
  22. this._baseRent = 900;
  23. this._waterUnitPrice = 40;
  24. this._electricUnitPrice = 90;
  25. this._accessToMainFacility = true;
  26. }
  27.  
  28. get storeName() {
  29. return this._storename;
  30. }
  31.  
  32. get locationNumber(){
  33. return this._locationNumber;
  34. }
  35.  
  36. get additionalWaterUnits() {
  37. return this._additionalWaterUnits;
  38. }
  39.  
  40. get additionalElectricityUnits() {
  41. return this._additionalElectricityUnits;
  42. }
  43.  
  44. revokeAccessToMainFacility() {
  45. this._accessToMainFacility = false;
  46. }
  47.  
  48. instateAccessToMainFacility() {
  49. this._accessToMainFacility = true;
  50. }
  51.  
  52. calculateTotalRent() {
  53. return this._baseRent + (this._waterUnitPrice * this._additionalWaterUnits) + (this._electricUnitPrice * this._additionalElectricityUnits);
  54. }
  55.  
  56. printTotalRent() {
  57. console.log('Rent for ' + this._storeName + ':' + '\n Base rent: $' + this._baseRent.toFixed(2) + '\n ' + this._additionalWaterUnits + ' additional water units at $' + this._waterUnitPrice.toFixed(2) + ' per unit \n ' + this._additionalElectricityUnits + ' additional electric units at $' + this._electricUnitPrice.toFixed(2) + ' per unit \n Total rent: $' + this.calculateTotalRent().toFixed(2));
  58. }
  59.  
  60. facilityManagerView() {
  61. let permitsValid;
  62. let inspectionsCurrent;
  63. let securityAccess;
  64. if (this.arePermitsValid === undefined){
  65. permitsValid = 'not applicable'
  66. }
  67. else {
  68. permitsValid = this.arePermitsValid;
  69. }
  70.  
  71. if (this.areInspectionsCurrent === undefined){
  72. inspectionsCurrent = 'not applicable';
  73. }
  74. else{
  75. inspectionsCurrent = this.areInspectionsCurrent;
  76. }
  77.  
  78. if (this._accessToMainFacility === true) {
  79. securityAccess = 'Granted';
  80. }
  81. else {
  82. securityAccess = 'Restricted'
  83. }
  84.  
  85. console.log(this._storeName + ' (location number ' + this._locationNumber + '): \n Security access: ' + securityAccess + '\n Total Rent: $' + this.calculateTotalRent().toFixed(2) + '\n Permits Valid: ' + permitsValid + '\n Inspections Current: ' + inspectionsCurrent);
  86. }
  87. }
  88.  
  89. class RetailStore extends Store {
  90. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits){
  91. super(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits);
  92. }
  93. }
  94.  
  95. class FoodSales extends Store {
  96. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits, permitsAsArray, numberOfAnnualInspections){
  97. super(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits);
  98. this._permitsAsArray = permitsAsArray;
  99. this._numberOfAnnualInspections = numberOfAnnualInspections;
  100. this._arePermitsValid = true;
  101. this._areInspectionsCurrent = true;
  102. }
  103.  
  104. get permitsAsArray() {
  105. return this._permitsAsArray;
  106. }
  107.  
  108. get numberOfAnnualInspections() {
  109. return this._numberOfAnnualInspections;
  110. }
  111.  
  112. get arePermitsValid() {
  113. return this._arePermitsValid;
  114. }
  115.  
  116. get areInspectionsCurrent() {
  117. return this._areInspectionsCurrent;
  118. }
  119.  
  120. invalidPermits() {
  121. this._arePermitsValid = false;
  122. }
  123.  
  124. allPermitsValid() {
  125. this._arePermitsValid = true;
  126. }
  127.  
  128. inspectionsNotCurrent() {
  129. this._areInspectionsCurrent = false;
  130. }
  131.  
  132. allInspectionsCurrent() {
  133. this._areInspectionsCurrent = true;
  134. }
  135.  
  136. requiredPermits() {
  137. let permitString = '';
  138. for (let i = 0; i < this._permitsAsArray.length; ++i) {
  139. permitString = permitString + this._permitsAsArray[i];
  140. if (i < this._permitsAsArray.length - 1) {
  141. permitString = permitString + ', ';
  142. }
  143. }
  144. console.log('Required permits for ' + this._storeName + ': ' + permitString);
  145. }
  146. }
  147.  
  148. const coolElectronics = new RetailStore('Cool Electronics', 302, 0, 4);
  149. // coolElectronics.printTotalRent();
  150. // coolElectronics.facilityManagerView();
  151. coolElectronics.revokeAccessToMainFacility();
  152. // coolElectronics.facilityManagerView();
  153. coolElectronics.instateAccessToMainFacility();
  154. coolElectronics.facilityManagerView();
  155.  
  156. const yummyNoms = new FoodSales('Yummy Noms', 222, 2, 1, ['Hot Fryer Permit', 'Large Dishwasher Permit'], 4);
  157. // yummyNoms.printTotalRent();
  158. yummyNoms.invalidPermits();
  159. yummyNoms.allPermitsValid();
  160. yummyNoms.inspectionsNotCurrent();
  161. yummyNoms.allInspectionsCurrent();
  162. yummyNoms.facilityManagerView();
  163. yummyNoms.requiredPermits();
  164.  
  165. const youNeedABurrito = new FoodSales('You Need a Burrito', 108, 1, 1, ['Spicy Ingredient Permit'], 4);
  166. youNeedABurrito.inspectionsNotCurrent();
  167. youNeedABurrito.invalidPermits();
  168. youNeedABurrito.facilityManagerView();
  169. youNeedABurrito.requiredPermits();
  170.  
  171. const genericAsianPandaDragonBuddhaName = new FoodSales('Generic Asian Panda Dragon Buddha Name', 145, 1, 0, ['Spicy Ingredient Permit', 'Hot Fryer Permit', 'Potential for Cat Meat Permit']);
  172. genericAsianPandaDragonBuddhaName.facilityManagerView();
  173. genericAsianPandaDragonBuddhaName.requiredPermits();
  174. </script>
  175.  
  176.  
  177.  
  178. <script id="jsbin-source-javascript" type="text/javascript">"use strict";
  179.  
  180. // this is some practice with "classes" in JS
  181.  
  182. // create my 'parent class'
  183. class Store {
  184. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits) {
  185. this._storeName = storeName;
  186. this._locationNumber = locationNumber;
  187. this._additionalWaterUnits = additionalWaterUnits;
  188. this._additionalElectricityUnits = additionalElectricityUnits;
  189. this._baseRent = 900;
  190. this._waterUnitPrice = 40;
  191. this._electricUnitPrice = 90;
  192. this._accessToMainFacility = true;
  193. }
  194.  
  195. get storeName() {
  196. return this._storename;
  197. }
  198.  
  199. get locationNumber(){
  200. return this._locationNumber;
  201. }
  202.  
  203. get additionalWaterUnits() {
  204. return this._additionalWaterUnits;
  205. }
  206.  
  207. get additionalElectricityUnits() {
  208. return this._additionalElectricityUnits;
  209. }
  210.  
  211. revokeAccessToMainFacility() {
  212. this._accessToMainFacility = false;
  213. }
  214.  
  215. instateAccessToMainFacility() {
  216. this._accessToMainFacility = true;
  217. }
  218.  
  219. calculateTotalRent() {
  220. return this._baseRent + (this._waterUnitPrice * this._additionalWaterUnits) + (this._electricUnitPrice * this._additionalElectricityUnits);
  221. }
  222.  
  223. printTotalRent() {
  224. console.log('Rent for ' + this._storeName + ':' + '\n Base rent: $' + this._baseRent.toFixed(2) + '\n ' + this._additionalWaterUnits + ' additional water units at $' + this._waterUnitPrice.toFixed(2) + ' per unit \n ' + this._additionalElectricityUnits + ' additional electric units at $' + this._electricUnitPrice.toFixed(2) + ' per unit \n Total rent: $' + this.calculateTotalRent().toFixed(2));
  225. }
  226.  
  227. facilityManagerView() {
  228. let permitsValid;
  229. let inspectionsCurrent;
  230. let securityAccess;
  231. if (this.arePermitsValid === undefined){
  232. permitsValid = 'not applicable'
  233. }
  234. else {
  235. permitsValid = this.arePermitsValid;
  236. }
  237.  
  238. if (this.areInspectionsCurrent === undefined){
  239. inspectionsCurrent = 'not applicable';
  240. }
  241. else{
  242. inspectionsCurrent = this.areInspectionsCurrent;
  243. }
  244.  
  245. if (this._accessToMainFacility === true) {
  246. securityAccess = 'Granted';
  247. }
  248. else {
  249. securityAccess = 'Restricted'
  250. }
  251.  
  252. console.log(this._storeName + ' (location number ' + this._locationNumber + '): \n Security access: ' + securityAccess + '\n Total Rent: $' + this.calculateTotalRent().toFixed(2) + '\n Permits Valid: ' + permitsValid + '\n Inspections Current: ' + inspectionsCurrent);
  253. }
  254. }
  255.  
  256. class RetailStore extends Store {
  257. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits){
  258. super(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits);
  259. }
  260. }
  261.  
  262. class FoodSales extends Store {
  263. constructor(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits, permitsAsArray, numberOfAnnualInspections){
  264. super(storeName, locationNumber, additionalWaterUnits, additionalElectricityUnits);
  265. this._permitsAsArray = permitsAsArray;
  266. this._numberOfAnnualInspections = numberOfAnnualInspections;
  267. this._arePermitsValid = true;
  268. this._areInspectionsCurrent = true;
  269. }
  270.  
  271. get permitsAsArray() {
  272. return this._permitsAsArray;
  273. }
  274.  
  275. get numberOfAnnualInspections() {
  276. return this._numberOfAnnualInspections;
  277. }
  278.  
  279. get arePermitsValid() {
  280. return this._arePermitsValid;
  281. }
  282.  
  283. get areInspectionsCurrent() {
  284. return this._areInspectionsCurrent;
  285. }
  286.  
  287. invalidPermits() {
  288. this._arePermitsValid = false;
  289. }
  290.  
  291. allPermitsValid() {
  292. this._arePermitsValid = true;
  293. }
  294.  
  295. inspectionsNotCurrent() {
  296. this._areInspectionsCurrent = false;
  297. }
  298.  
  299. allInspectionsCurrent() {
  300. this._areInspectionsCurrent = true;
  301. }
  302.  
  303. requiredPermits() {
  304. let permitString = '';
  305. for (let i = 0; i < this._permitsAsArray.length; ++i) {
  306. permitString = permitString + this._permitsAsArray[i];
  307. if (i < this._permitsAsArray.length - 1) {
  308. permitString = permitString + ', ';
  309. }
  310. }
  311. console.log('Required permits for ' + this._storeName + ': ' + permitString);
  312. }
  313. }
  314.  
  315. const coolElectronics = new RetailStore('Cool Electronics', 302, 0, 4);
  316. // coolElectronics.printTotalRent();
  317. // coolElectronics.facilityManagerView();
  318. coolElectronics.revokeAccessToMainFacility();
  319. // coolElectronics.facilityManagerView();
  320. coolElectronics.instateAccessToMainFacility();
  321. coolElectronics.facilityManagerView();
  322.  
  323. const yummyNoms = new FoodSales('Yummy Noms', 222, 2, 1, ['Hot Fryer Permit', 'Large Dishwasher Permit'], 4);
  324. // yummyNoms.printTotalRent();
  325. yummyNoms.invalidPermits();
  326. yummyNoms.allPermitsValid();
  327. yummyNoms.inspectionsNotCurrent();
  328. yummyNoms.allInspectionsCurrent();
  329. yummyNoms.facilityManagerView();
  330. yummyNoms.requiredPermits();
  331.  
  332. const youNeedABurrito = new FoodSales('You Need a Burrito', 108, 1, 1, ['Spicy Ingredient Permit'], 4);
  333. youNeedABurrito.inspectionsNotCurrent();
  334. youNeedABurrito.invalidPermits();
  335. youNeedABurrito.facilityManagerView();
  336. youNeedABurrito.requiredPermits();
  337.  
  338. const genericAsianPandaDragonBuddhaName = new FoodSales('Generic Asian Panda Dragon Buddha Name', 145, 1, 0, ['Spicy Ingredient Permit', 'Hot Fryer Permit', 'Potential for Cat Meat Permit']);
  339. genericAsianPandaDragonBuddhaName.facilityManagerView();
  340. genericAsianPandaDragonBuddhaName.requiredPermits();</script></body>
  341. </html>
Add Comment
Please, Sign In to add comment