Last active
February 25, 2023 08:25
-
-
Save enseitankad0/d059fbe1803dc0701d54bee19ef9ff37 to your computer and use it in GitHub Desktop.
Printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kamilszufnara; | |
public class Main { | |
// Create a class and demonstate proper encapsulation techniques | |
// the class will be called Printer | |
// It will simulate a real Computer Printer | |
// It should have fields for the toner Level, number of pages printed, and | |
// also whether its a duplex printer (capable of printing on both sides of the paper). | |
// Add methods to fill up the toner (up to a maximum of 100%), another method to | |
// simulate printing a page (which should increase the number of pages printed). | |
// Decide on the scope, whether to use constructors, and anything else you think is needed. | |
public static void main(String[] args) { | |
Printer printer = new Printer(80,0,true); | |
printer.fillUpTonner(15); | |
printer.printPage(11); | |
//wersja hermatyczna? | |
System.out.println("\nMethod 2 \n" + | |
"now toner level is: " + printer.getTonerLevel() + "\n" + | |
"now counter is: " + printer.getCounter()); | |
// System.out.println(); | |
// System.out.println("Creating a printer without duplex"); | |
// Printer printer2 = new Printer(80,0,false); | |
// printer2.printPage(100); | |
// printer.printPage(22); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kamilszufnara; | |
public class Printer { | |
private int tonerLevel; | |
private int numberOfPages; | |
private boolean isDuplex; | |
public Printer(int tonerLevel, int numberOfPages, boolean isDuplex) { | |
this.tonerLevel = tonerLevel; | |
this.numberOfPages = numberOfPages; | |
this.isDuplex = isDuplex; | |
} | |
public void fillUpTonner(int blackMatter) { | |
this.tonerLevel = this.tonerLevel + blackMatter; | |
if (this.tonerLevel > 100) { | |
int rest = blackMatter + 100 - tonerLevel; | |
System.out.println("tonner container overfilled"); | |
System.out.println("maximum amount of toner you can use is " + rest + "Tonner was filled up to 100% using this amount"); | |
} else { | |
System.out.println("Filling. Now printer toner container level: " + this.tonerLevel); | |
} | |
} | |
public void printPage(int howManyPages) { | |
// printing with duplex | |
if (isDuplex == true) { | |
System.out.println("duplex is working"); | |
this.numberOfPages += (howManyPages/2) + (howManyPages%2); | |
} else { | |
System.out.println("duplex is not working"); | |
this.numberOfPages += howManyPages;} | |
System.out.println("printer is printing " + howManyPages + " pages "); | |
System.out.println("the counter of printed paper pages is: " + this.numberOfPages); | |
} | |
public int getTonerLevel() { | |
return tonerLevel; | |
} | |
public int getCounter() { | |
return this.numberOfPages; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment