SHARE
TWEET

Untitled

a guest Sep 15th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Demo {
  2.     public static void main(String[] args) throws Exception {
  3.         XPCounter counter = new XPCounter();
  4.         int actionTimer = 0;
  5.         int xpGained = 0;
  6.  
  7.         while(true) {
  8.             if(++actionTimer > 5) {
  9.                 actionTimer = 0;
  10.                 xpGained++;
  11.             }
  12.  
  13.             int xpPerHour = counter.calculateXpPerHour(xpGained);
  14.             System.out.printf("XP Per Hour: \t%d%n", xpPerHour);
  15.             Thread.sleep(60);
  16.         }
  17.     }
  18. }
  19.  
  20. class XPCounter {
  21.     private final long startTime = System.currentTimeMillis();
  22.  
  23.     int calculateXpPerHour(int xpGained) {
  24.         long elapsedMilliseconds = System.currentTimeMillis() - startTime;
  25.         boolean minuteHasPassed = elapsedMilliseconds >= 60_000;
  26.  
  27.         int xpPerHour;
  28.         if(minuteHasPassed) {
  29.             double elapsedHours = (double) elapsedMilliseconds / 3_600_000d;
  30.             xpPerHour = (int) (xpGained / elapsedHours);
  31.         } else {
  32.             xpPerHour = xpGained * 60;
  33.         }
  34.  
  35.         return xpPerHour;
  36.     }
  37. }
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