Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package com.un4;
  2.  
  3. /**
  4. * Created by UN4CKN0WL3Z on 22/08/2017.
  5. */
  6. public class Printer {
  7.  
  8. private int tonerLevel;
  9. private int pagesPrinted;
  10. private boolean duplex;
  11.  
  12. public Printer(int tonerLevel, boolean duplex) {
  13.  
  14.  
  15. if(tonerLevel > -1 && tonerLevel <= 100){
  16. this.tonerLevel = tonerLevel;
  17. }else{
  18. this.tonerLevel = -1;
  19. }
  20.  
  21.  
  22. this.duplex = duplex;
  23. this.pagesPrinted = 0;
  24.  
  25. }
  26.  
  27. public int addToner(int tonerAmount){
  28. if(tonerAmount > 0 && tonerAmount <= 100){
  29. if(this.tonerLevel + tonerAmount > 100){
  30. return -1;
  31. }
  32. this.tonerLevel =+ tonerAmount;
  33. return this.tonerLevel;
  34. }else{
  35. return -1;
  36. }
  37.  
  38. }
  39.  
  40.  
  41. public int printPages(int pages){
  42.  
  43. int pagesToPrint = pages;
  44. if(this.duplex){
  45. pagesToPrint /= 2;
  46. System.out.println("Printing in duplex mode");
  47. }
  48. this.pagesPrinted += pagesToPrint;
  49. return pagesToPrint;
  50.  
  51. }
  52.  
  53. public int getPagesPrinted() {
  54. return pagesPrinted;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement