Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.JakubSzymanski;
- public class Printer {
- private double cyanTonerPercentage;
- private double magentaTonerPercentage;
- private double yellowTonerPercentage;
- private double blackTonerPercentage;
- private int pagesPrinted;
- private int sheetsOfPaper;
- private boolean isDuplex;
- private boolean isBroken;
- public Printer(double cyanTonerPercentage, double magentaTonerPercentage, double yellowTonerPercentage, double blackTonerPercentage, int pagesPrinted, int sheetsOfPaper, boolean isDuplex, boolean isBroken) {
- if (cyanTonerPercentage < 0) {
- this.cyanTonerPercentage = 0;
- } else if (cyanTonerPercentage > 100) {
- this.cyanTonerPercentage = 100;
- } else {
- this.cyanTonerPercentage = cyanTonerPercentage;
- }
- if (magentaTonerPercentage < 0) {
- this.magentaTonerPercentage = 0;
- } else if (magentaTonerPercentage > 100) {
- this.magentaTonerPercentage = 100;
- } else {
- this.magentaTonerPercentage = magentaTonerPercentage;
- }
- if (yellowTonerPercentage < 0) {
- this.yellowTonerPercentage = 0;
- } else if (yellowTonerPercentage > 100) {
- this.yellowTonerPercentage = 100;
- } else {
- this.yellowTonerPercentage = yellowTonerPercentage;
- }
- if (blackTonerPercentage < 0) {
- this.blackTonerPercentage = 0;
- } else if (blackTonerPercentage > 100) {
- this.blackTonerPercentage = 100;
- } else {
- this.blackTonerPercentage = blackTonerPercentage;
- }
- if (pagesPrinted < 0) {
- this.pagesPrinted = 0;
- } else {
- this.pagesPrinted = pagesPrinted;
- }
- if (sheetsOfPaper < 0) {
- this.sheetsOfPaper = 0;
- } else if (sheetsOfPaper > 100) {
- this.sheetsOfPaper = 100;
- } else {
- this.sheetsOfPaper = sheetsOfPaper;
- }
- this.isDuplex = isDuplex;
- this.isBroken = isBroken;
- }
- public Printer(double cyanTonerPercentage, double magentaTonerPercentage, double yellowTonerPercentage, double blackTonerPercentage, boolean isDuplex) {
- this(cyanTonerPercentage, magentaTonerPercentage, yellowTonerPercentage, blackTonerPercentage, 0,0, isDuplex, false);
- }
- public Printer(boolean isDuplex) {
- this(0, 0, 0, 0, isDuplex);
- }
- public Printer() {
- this(false);
- }
- public double getCyanTonerPercentage() {
- return cyanTonerPercentage;
- }
- public void setCyanTonerPercentage(double cyanTonerPercentage) {
- if (cyanTonerPercentage < 0) {
- this.cyanTonerPercentage = 0;
- } else if (cyanTonerPercentage > 100) {
- this.cyanTonerPercentage = 100;
- } else {
- this.cyanTonerPercentage = cyanTonerPercentage;
- }
- }
- public void changeAmountOfCyanToner(double tonerAmount) {
- if (this.cyanTonerPercentage + tonerAmount > 100) {
- System.out.println("Cyan toner has spilled. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- this.cyanTonerPercentage = 100;
- } else if (this.cyanTonerPercentage + tonerAmount < 0) {
- System.out.println("I dunno vvat hef u don with dat cyan toner, but Im confundus.");
- this.cyanTonerPercentage = 0;
- } else {
- this.cyanTonerPercentage += tonerAmount;
- }
- }
- public double getMagentaTonerPercentage() {
- return magentaTonerPercentage;
- }
- public void setMagentaTonerPercentage(double magentaTonerPercentage) {
- if (magentaTonerPercentage < 0) {
- this.magentaTonerPercentage = 0;
- } else if (magentaTonerPercentage > 100) {
- this.magentaTonerPercentage = 100;
- } else {
- this.magentaTonerPercentage = magentaTonerPercentage;
- }
- }
- public void changeAmountOfMagentaToner(double tonerAmount) {
- if (this.magentaTonerPercentage + tonerAmount > 100) {
- System.out.println("Magenta toner has spilled. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- this.magentaTonerPercentage = 100;
- } else if (this.magentaTonerPercentage + tonerAmount < 0) {
- System.out.println("I dunno vvat hef u don with dat magenta toner, but Im confundus.");
- this.magentaTonerPercentage = 0;
- } else {
- this.magentaTonerPercentage += tonerAmount;
- }
- }
- public double getYellowTonerPercentage() {
- return yellowTonerPercentage;
- }
- public void setYellowTonerPercentage(double yellowTonerPercentage) {
- if (yellowTonerPercentage < 0) {
- this.yellowTonerPercentage = 0;
- } else if (yellowTonerPercentage > 100) {
- this.yellowTonerPercentage = 100;
- } else {
- this.yellowTonerPercentage = yellowTonerPercentage;
- }
- }
- public void changeAmountOfYellowToner(double tonerAmount) {
- if (this.yellowTonerPercentage + tonerAmount > 100) {
- System.out.println("Yellow toner has spilled. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- this.yellowTonerPercentage = 100;
- } else if (this.yellowTonerPercentage + tonerAmount < 0) {
- System.out.println("I dunno vvat hef u don with dat yellow toner, but Im confundus.");
- this.yellowTonerPercentage = 0;
- } else {
- this.yellowTonerPercentage += tonerAmount;
- }
- }
- public double getBlackTonerPercentage() {
- return blackTonerPercentage;
- }
- public void setBlackTonerPercentage(double blackTonerPercentage) {
- if (blackTonerPercentage < 0) {
- this.blackTonerPercentage = 0;
- } else if (blackTonerPercentage > 100) {
- this.blackTonerPercentage = 100;
- } else {
- this.blackTonerPercentage = blackTonerPercentage;
- }
- }
- public void changeAmountOfBlackToner(double tonerAmount) {
- if (this.blackTonerPercentage + tonerAmount > 100) {
- System.out.println("Black toner has spilled. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- this.blackTonerPercentage = 100;
- } else if (this.blackTonerPercentage + tonerAmount < 0) {
- System.out.println("I dunno vvat hef u don with dat black toner, but Im confundus.");
- this.blackTonerPercentage = 0;
- } else {
- this.blackTonerPercentage += tonerAmount;
- }
- }
- public int getPagesPrinted() {
- return pagesPrinted;
- }
- public void resetPagesPrinted() {
- this.pagesPrinted = 0;
- }
- public int getSheetsOfPaper() {
- return sheetsOfPaper;
- }
- public void setSheetsOfPaper(int sheetsOfPaper) {
- if (sheetsOfPaper < 0) {
- this.sheetsOfPaper = 0;
- } else if (sheetsOfPaper > 100) {
- this.sheetsOfPaper = 100;
- System.out.println("Paper shelf has overloaded. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- } else {
- this.sheetsOfPaper = sheetsOfPaper;
- }
- }
- public void changeAmountOfpaper(int amountOfPaper) {
- if (this.sheetsOfPaper + amountOfPaper > 100) {
- System.out.println("Paper shelf has overloaded. You have to be more careful. Printer is broken now.");
- this.isBroken = true;
- this.sheetsOfPaper = 100;
- } else if (this.sheetsOfPaper + amountOfPaper < 0) {
- System.out.println("I dunno vvat hef u don with dat paper, but Im confundus.");
- this.sheetsOfPaper = 0;
- } else {
- this.sheetsOfPaper += amountOfPaper;
- }
- }
- public boolean isDuplex() {
- return isDuplex;
- }
- public boolean isBroken() {
- return isBroken;
- }
- public void setIsBroken(boolean isBroken) {
- this.isBroken = isBroken;
- }
- public void printPages(int amountOfPages) {
- if (amountOfPages < 100 && amountOfPages > 0){
- if (!this.isBroken) {
- if (isDuplex) {
- if (amountOfPages % 2 == 0) {
- if (amountOfPages / 2 < this.sheetsOfPaper) {
- this.sheetsOfPaper -= (amountOfPages / 2);
- this.pagesPrinted += (amountOfPages / 2);
- } else {
- System.out.println("There are not enough sheets of paper.");
- }
- } else {
- if (amountOfPages / 2 + 1 < this.sheetsOfPaper) {
- this.sheetsOfPaper -= (amountOfPages / 2) + 1;
- this.pagesPrinted += (amountOfPages / 2) + 1;
- } else {
- System.out.println("There are not enough sheets of paper.");
- }
- }
- } else {
- if (amountOfPages < this.sheetsOfPaper) {
- this.sheetsOfPaper -= amountOfPages;
- this.pagesPrinted += amountOfPages;
- } else {
- System.out.println("There are not enough sheets of paper.");
- }
- }
- } else {
- System.out.println("Printer is OUT OF ORDER.");
- }
- } else {
- System.out.println("Invalid value of pages.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement