ENCAPSULATION CHALLENGE
package com.cnc ; public class Main { public static void main ( String [] args) { Printer printer = new Printer( 50 , true ); System . out .println( "Initial Page count is " + printer .getNumberOfPages()); int pagesPrinted = printer .getNumberOfPages( 4 ); } } package com.cnc ; public class Printer { private int tonerLevel = 100 ; private int numberOfPages ; private boolean isDuplex ; public Printer ( int tonerLevel, boolean isDuplex) { if (tonerLevel>=- 1 && tonerLevel<= 100 ) { this . tonerLevel = tonerLevel; } else { this . tonerLevel =- 1 ; } this . isDuplex = isDuplex; this . numberOfPages = 0 ; } public int addToner ( int tonerAmount){ if (tonerAmount> 0 && tonerAmount<= 100 ){ if ( this . tonerLevel +tonerAmount > 100 ){ return - 1 ; } this . tonerLevel += tonerAmount