Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.73 KB | None | 0 0
  1. package com.JakubSzymanski;
  2.  
  3. public class Printer {
  4.     private double cyanTonerPercentage;
  5.     private double magentaTonerPercentage;
  6.     private double yellowTonerPercentage;
  7.     private double blackTonerPercentage;
  8.     private int pagesPrinted;
  9.     private int sheetsOfPaper;
  10.     private boolean isDuplex;
  11.     private boolean isBroken;
  12.  
  13.     public Printer(double cyanTonerPercentage, double magentaTonerPercentage, double yellowTonerPercentage, double blackTonerPercentage, int pagesPrinted, int sheetsOfPaper, boolean isDuplex, boolean isBroken) {
  14.         if (cyanTonerPercentage < 0) {
  15.             this.cyanTonerPercentage = 0;
  16.         } else if (cyanTonerPercentage > 100) {
  17.             this.cyanTonerPercentage = 100;
  18.         } else {
  19.             this.cyanTonerPercentage = cyanTonerPercentage;
  20.         }
  21.         if (magentaTonerPercentage < 0) {
  22.             this.magentaTonerPercentage = 0;
  23.         } else if (magentaTonerPercentage > 100) {
  24.             this.magentaTonerPercentage = 100;
  25.         } else {
  26.             this.magentaTonerPercentage = magentaTonerPercentage;
  27.         }
  28.         if (yellowTonerPercentage < 0) {
  29.             this.yellowTonerPercentage = 0;
  30.         } else if (yellowTonerPercentage > 100) {
  31.             this.yellowTonerPercentage = 100;
  32.         } else {
  33.             this.yellowTonerPercentage = yellowTonerPercentage;
  34.         }
  35.         if (blackTonerPercentage < 0) {
  36.             this.blackTonerPercentage = 0;
  37.         } else if (blackTonerPercentage > 100) {
  38.             this.blackTonerPercentage = 100;
  39.         } else {
  40.             this.blackTonerPercentage = blackTonerPercentage;
  41.         }
  42.         if (pagesPrinted < 0) {
  43.             this.pagesPrinted = 0;
  44.         } else {
  45.             this.pagesPrinted = pagesPrinted;
  46.         }
  47.         if (sheetsOfPaper < 0) {
  48.             this.sheetsOfPaper = 0;
  49.         } else if (sheetsOfPaper > 100) {
  50.             this.sheetsOfPaper = 100;
  51.         } else {
  52.             this.sheetsOfPaper = sheetsOfPaper;
  53.         }
  54.         this.isDuplex = isDuplex;
  55.         this.isBroken = isBroken;
  56.     }
  57.  
  58.     public Printer(double cyanTonerPercentage, double magentaTonerPercentage, double yellowTonerPercentage, double blackTonerPercentage, boolean isDuplex) {
  59.         this(cyanTonerPercentage, magentaTonerPercentage, yellowTonerPercentage, blackTonerPercentage, 0,0, isDuplex, false);
  60.  
  61.     }
  62.  
  63.     public Printer(boolean isDuplex) {
  64.         this(0, 0, 0, 0, isDuplex);
  65.     }
  66.  
  67.     public Printer() {
  68.         this(false);
  69.     }
  70.  
  71.     public double getCyanTonerPercentage() {
  72.         return cyanTonerPercentage;
  73.     }
  74.  
  75.     public void setCyanTonerPercentage(double cyanTonerPercentage) {
  76.         if (cyanTonerPercentage < 0) {
  77.             this.cyanTonerPercentage = 0;
  78.         } else if (cyanTonerPercentage > 100) {
  79.             this.cyanTonerPercentage = 100;
  80.         } else {
  81.             this.cyanTonerPercentage = cyanTonerPercentage;
  82.         }
  83.     }
  84.  
  85.     public void changeAmountOfCyanToner(double tonerAmount) {
  86.         if (this.cyanTonerPercentage + tonerAmount > 100) {
  87.             System.out.println("Cyan toner has spilled. You have to be more careful. Printer is broken now.");
  88.             this.isBroken = true;
  89.             this.cyanTonerPercentage = 100;
  90.         } else if (this.cyanTonerPercentage + tonerAmount < 0) {
  91.             System.out.println("I dunno vvat hef u don with dat cyan toner, but Im confundus.");
  92.             this.cyanTonerPercentage = 0;
  93.         } else {
  94.             this.cyanTonerPercentage += tonerAmount;
  95.         }
  96.     }
  97.  
  98.     public double getMagentaTonerPercentage() {
  99.         return magentaTonerPercentage;
  100.     }
  101.  
  102.     public void setMagentaTonerPercentage(double magentaTonerPercentage) {
  103.         if (magentaTonerPercentage < 0) {
  104.             this.magentaTonerPercentage = 0;
  105.         } else if (magentaTonerPercentage > 100) {
  106.             this.magentaTonerPercentage = 100;
  107.         } else {
  108.             this.magentaTonerPercentage = magentaTonerPercentage;
  109.         }
  110.     }
  111.  
  112.     public void changeAmountOfMagentaToner(double tonerAmount) {
  113.         if (this.magentaTonerPercentage + tonerAmount > 100) {
  114.             System.out.println("Magenta toner has spilled. You have to be more careful. Printer is broken now.");
  115.             this.isBroken = true;
  116.             this.magentaTonerPercentage = 100;
  117.         } else if (this.magentaTonerPercentage + tonerAmount < 0) {
  118.             System.out.println("I dunno vvat hef u don with dat magenta toner, but Im confundus.");
  119.             this.magentaTonerPercentage = 0;
  120.         } else {
  121.             this.magentaTonerPercentage += tonerAmount;
  122.         }
  123.     }
  124.  
  125.     public double getYellowTonerPercentage() {
  126.         return yellowTonerPercentage;
  127.     }
  128.  
  129.     public void setYellowTonerPercentage(double yellowTonerPercentage) {
  130.         if (yellowTonerPercentage < 0) {
  131.             this.yellowTonerPercentage = 0;
  132.         } else if (yellowTonerPercentage > 100) {
  133.             this.yellowTonerPercentage = 100;
  134.         } else {
  135.             this.yellowTonerPercentage = yellowTonerPercentage;
  136.         }
  137.     }
  138.  
  139.     public void changeAmountOfYellowToner(double tonerAmount) {
  140.         if (this.yellowTonerPercentage + tonerAmount > 100) {
  141.             System.out.println("Yellow toner has spilled. You have to be more careful. Printer is broken now.");
  142.             this.isBroken = true;
  143.             this.yellowTonerPercentage = 100;
  144.         } else if (this.yellowTonerPercentage + tonerAmount < 0) {
  145.             System.out.println("I dunno vvat hef u don with dat yellow toner, but Im confundus.");
  146.             this.yellowTonerPercentage = 0;
  147.         } else {
  148.             this.yellowTonerPercentage += tonerAmount;
  149.         }
  150.     }
  151.  
  152.     public double getBlackTonerPercentage() {
  153.         return blackTonerPercentage;
  154.     }
  155.  
  156.     public void setBlackTonerPercentage(double blackTonerPercentage) {
  157.         if (blackTonerPercentage < 0) {
  158.             this.blackTonerPercentage = 0;
  159.         } else if (blackTonerPercentage > 100) {
  160.             this.blackTonerPercentage = 100;
  161.         } else {
  162.             this.blackTonerPercentage = blackTonerPercentage;
  163.         }
  164.     }
  165.  
  166.     public void changeAmountOfBlackToner(double tonerAmount) {
  167.         if (this.blackTonerPercentage + tonerAmount > 100) {
  168.             System.out.println("Black toner has spilled. You have to be more careful. Printer is broken now.");
  169.             this.isBroken = true;
  170.             this.blackTonerPercentage = 100;
  171.         } else if (this.blackTonerPercentage + tonerAmount < 0) {
  172.             System.out.println("I dunno vvat hef u don with dat black toner, but Im confundus.");
  173.             this.blackTonerPercentage = 0;
  174.         } else {
  175.             this.blackTonerPercentage += tonerAmount;
  176.         }
  177.     }
  178.  
  179.     public int getPagesPrinted() {
  180.         return pagesPrinted;
  181.     }
  182.  
  183.     public void resetPagesPrinted() {
  184.         this.pagesPrinted = 0;
  185.     }
  186.  
  187.     public int getSheetsOfPaper() {
  188.         return sheetsOfPaper;
  189.     }
  190.  
  191.     public void setSheetsOfPaper(int sheetsOfPaper) {
  192.         if (sheetsOfPaper < 0) {
  193.             this.sheetsOfPaper = 0;
  194.         } else if (sheetsOfPaper > 100) {
  195.             this.sheetsOfPaper = 100;
  196.             System.out.println("Paper shelf has overloaded. You have to be more careful. Printer is broken now.");
  197.             this.isBroken = true;
  198.         } else {
  199.             this.sheetsOfPaper = sheetsOfPaper;
  200.         }
  201.     }
  202.  
  203.     public void changeAmountOfpaper(int amountOfPaper) {
  204.         if (this.sheetsOfPaper + amountOfPaper > 100) {
  205.             System.out.println("Paper shelf has overloaded. You have to be more careful. Printer is broken now.");
  206.             this.isBroken = true;
  207.             this.sheetsOfPaper = 100;
  208.         } else if (this.sheetsOfPaper + amountOfPaper < 0) {
  209.             System.out.println("I dunno vvat hef u don with dat paper, but Im confundus.");
  210.             this.sheetsOfPaper = 0;
  211.         } else {
  212.             this.sheetsOfPaper += amountOfPaper;
  213.         }
  214.     }
  215.  
  216.     public boolean isDuplex() {
  217.         return isDuplex;
  218.     }
  219.  
  220.     public boolean isBroken() {
  221.         return isBroken;
  222.     }
  223.  
  224.     public void setIsBroken(boolean isBroken) {
  225.         this.isBroken = isBroken;
  226.     }
  227.  
  228.     public void printPages(int amountOfPages) {
  229.         if (amountOfPages < 100 && amountOfPages > 0){
  230.             if (!this.isBroken) {
  231.                 if (isDuplex) {
  232.                     if (amountOfPages % 2 == 0) {
  233.                         if (amountOfPages / 2 < this.sheetsOfPaper) {
  234.                             this.sheetsOfPaper -= (amountOfPages / 2);
  235.                             this.pagesPrinted += (amountOfPages / 2);
  236.                         } else {
  237.                             System.out.println("There are not enough sheets of paper.");
  238.                         }
  239.  
  240.                     } else {
  241.                         if (amountOfPages / 2 + 1 < this.sheetsOfPaper) {
  242.                             this.sheetsOfPaper -= (amountOfPages / 2) + 1;
  243.                             this.pagesPrinted += (amountOfPages / 2) + 1;
  244.                         } else {
  245.                             System.out.println("There are not enough sheets of paper.");
  246.                         }
  247.                     }
  248.                 } else {
  249.                     if (amountOfPages < this.sheetsOfPaper) {
  250.                         this.sheetsOfPaper -= amountOfPages;
  251.                         this.pagesPrinted += amountOfPages;
  252.                     } else {
  253.                         System.out.println("There are not enough sheets of paper.");
  254.                     }
  255.                 }
  256.             } else {
  257.                 System.out.println("Printer is OUT OF ORDER.");
  258.             }
  259.         } else {
  260.             System.out.println("Invalid value of pages.");
  261.         }
  262.     }
  263.  
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement