SHARE
TWEET

Untitled

a guest Sep 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package hw1;
  2.  
  3. public class WirelessPrinter {
  4.     public static final int PAGES_PER_CARTRIDGE = 1000;
  5.     public static final int TRAY_CAPACITY = 500;
  6.     public static final double NEW_CARTRIDGE_INK_LEVEL = 1.0;
  7.    
  8.     private int paperlevel;
  9.     private double inklevel;
  10.     private boolean on;
  11.     private boolean connected;
  12.     private int pagesprinted;
  13.  
  14.     public WirelessPrinter(double ink, int paper){
  15.         inklevel = Math.min(ink, NEW_CARTRIDGE_INK_LEVEL);
  16.         paperlevel = Math.min(paper, TRAY_CAPACITY);
  17.     }
  18.     /*public WirelessPrinter(boolean On, boolean Connected, int PaperLevel, double InkLevel)
  19.     {
  20.         on = On;
  21.         connected = Connected;
  22.         paperlevel = PaperLevel;
  23.         inklevel = InkLevel;
  24.     }
  25.  
  26.     public WirelessPrinter(double ink, int paper)
  27.     {
  28.         ink = 0.5;
  29.         paper = 500;
  30.  
  31.     }*/
  32.  
  33.     private void connect() {
  34.         connected = true;
  35.     }
  36.  
  37.     public int getPaperLevelExact()
  38.     {
  39.         return paperlevel;
  40.     }
  41.  
  42.     public void turnOn()
  43.     {
  44.         on = true;
  45.         connect();
  46.     }
  47.     public boolean isOn()
  48.     {
  49.         return on;
  50.     }
  51.    
  52.     public boolean isConnected()
  53.     {
  54.         return connected;
  55.     }
  56.    
  57.    
  58.    
  59.     public int getPaperLevel() // return a percentage
  60.     {
  61.         return (int)Math.round(((double)paperlevel/(double)TRAY_CAPACITY)*100);
  62.     }
  63.    
  64.     public double getInkLevel()
  65.     {
  66.         return inklevel;
  67.     }
  68.    
  69.     public int getTotalPagesPrinted()
  70.     {
  71.         return pagesprinted;
  72.     }
  73.    
  74.     public int getTotalPaperUsed()
  75.     {
  76.         return pagesprinted;
  77.     }
  78.    
  79.    
  80.     public void loadPaper(int paperLoaded)
  81.     {
  82.         if (isConnected()) {
  83.             paperlevel = Math.min(paperlevel + paperLoaded, TRAY_CAPACITY);
  84.         }
  85.     }
  86.  
  87.     public void print(int addedPages)
  88.     {
  89.         if (isConnected()) {
  90.             int allowedPagesPrinted;
  91.             allowedPagesPrinted = Math.min(paperlevel, addedPages);
  92.             pagesprinted = pagesprinted + allowedPagesPrinted;
  93.             paperlevel = Math.max(0, paperlevel - addedPages);
  94.             inklevel = Math.max(NEW_CARTRIDGE_INK_LEVEL - ((NEW_CARTRIDGE_INK_LEVEL / PAGES_PER_CARTRIDGE) * pagesprinted), 0);
  95.         }
  96.     }
  97.    
  98.     public void replaceCartridge()
  99.     {
  100.         if (isConnected()) {
  101.             inklevel = NEW_CARTRIDGE_INK_LEVEL;
  102.         }
  103.     }
  104.    
  105.     public void disconnect()
  106.     {
  107.         connected = false;
  108.     }
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top