Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Demo {
- public static void main(String[] args) throws Exception {
- XPCounter counter = new XPCounter();
- int actionTimer = 0;
- int xpGained = 0;
- while(true) {
- if(++actionTimer > 5) {
- actionTimer = 0;
- xpGained++;
- }
- int xpPerHour = counter.calculateXpPerHour(xpGained);
- System.out.printf("XP Per Hour: \t%d%n", xpPerHour);
- Thread.sleep(60);
- }
- }
- }
- class XPCounter {
- private final long startTime = System.currentTimeMillis();
- int calculateXpPerHour(int xpGained) {
- long elapsedMilliseconds = System.currentTimeMillis() - startTime;
- boolean minuteHasPassed = elapsedMilliseconds >= 60_000;
- int xpPerHour;
- if(minuteHasPassed) {
- double elapsedHours = (double) elapsedMilliseconds / 3_600_000d;
- xpPerHour = (int) (xpGained / elapsedHours);
- } else {
- xpPerHour = xpGained * 60;
- }
- return xpPerHour;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement