Guest User

Untitled

a guest
May 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. class Printer {
  2. constructor(label = "Unknown", pageSize = "A4", amountOfDye = 100, amountOfPaper = 50, powerState = "off") {
  3. this.label = label;
  4. this.pageSize = pageSize;
  5. this.amountOfDye = amountOfDye;
  6. this.amountOfPaper = amountOfPaper;
  7. this.powerState = powerState;
  8. }
  9. addPaper(amount) {
  10. this.amountOfPaper += amount;
  11. }
  12. fillCartridge(amount) {
  13. this.amountOfDye += amount;
  14. }
  15. turnOn() {
  16. this.powerState = "on";
  17. }
  18. turnOff() {
  19. this.powerState = "off";
  20. }
  21. setPageSize(size) {
  22. this.pageSize = size;
  23. }
  24. print(amount) {
  25. if (this.powerState != "on") {
  26. console.log("Printer is off");
  27. return;
  28. }
  29. for (let i = 0; i < amount; i++) {
  30. if (this.amountOfDye == 0)
  31. console.log("Fill the cartridge!");
  32. if (this.amountOfPaper == 0)
  33. console.log("Please, add paper to printer");
  34. if (this.amountOfDye == 0 || this.amountOfPaper == 0) return;
  35. this.amountOfDye -= 1;
  36. this.amountOfPaper -= 1;
  37. }
  38. }
  39. info() {
  40. console.log("Name: ", this.label);
  41. console.log("Amount of paper: ", this.amountOfPaper);
  42. console.log("Amount of dye: ", this.amountOfDye);
  43. console.log("Page size: ", this.pageSize);
  44. console.log("Power state: ", this.powerState);
  45. }
  46. }
  47.  
  48. let printer = new Printer();
Add Comment
Please, Sign In to add comment