Popcorn Hack 1

class PowerLevelCalc {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter your level: ");
        int level = sc.nextInt();

        double basePower = 100;
        double finalPower = basePower * Math.pow(1.2, level);

        System.out.println("Level: " + level);
        System.out.println("Base Power: " + basePower);
        System.out.printf("Final Power: %.2f%n", finalPower);

        sc.close();
    }
}

PowerLevelCalc.main(null);

Enter your level: Level: 2
Base Power: 100.0
Final Power: 144.00

Popcorn Hack 2

class LootDropSimulator {
    public static void main(String[] args) {
        System.out.println("Loot Drop!");

        // Generate rarity roll between 1 and 100
        int rarityRoll = (int)(Math.random() * 100) + 1;
        System.out.println("Rarity Roll: " + rarityRoll);

        String rarity;
        int goldValue;

        if (rarityRoll <= 60) {
            rarity = "COMMON";
            goldValue = (int)(Math.random() * (30 - 10 + 1)) + 10;
        } else if (rarityRoll <= 85) {
            rarity = "RARE";
            goldValue = (int)(Math.random() * (70 - 31 + 1)) + 31;
        } else {
            rarity = "LEGENDARY";
            goldValue = (int)(Math.random() * (100 - 71 + 1)) + 71;
        }

        System.out.println("You got: " + rarity + " item");
        System.out.println("Gold Value: " + goldValue);
    }
}

LootDropSimulator.main(null);

Loot Drop!
Rarity Roll: 6
You got: COMMON item
Gold Value: 18

Homework

MCQ answers

  1. A
  2. A
  3. B
  4. A
  5. B

Game Stats Calculator

class GameStatsCalculator {

    // Part A: Health Difference Calculator
    public static int healthDifference(int player1Health, int player2Health) {
        return Math.abs(player1Health - player2Health);
    }

    // Part B: Attack Damage Calculator
    public static double calculateDamage(double baseDamage, double powerLevel) {
        return baseDamage * Math.pow(1.5, powerLevel);
    }

    // Part C: Distance Detector
    public static double findDistance(int playerX, int playerY, int enemyX, int enemyY) {
        return Math.sqrt(Math.pow(enemyX - playerX, 2) + Math.pow(enemyY - playerY, 2));
    }

    // Part D: Random Loot Generator
    public static int generateLoot(int minValue, int maxValue) {
        return (int)(Math.random() * (maxValue - minValue + 1)) + minValue;
    }

    public static void main(String[] args) {
        // Test Part A
        System.out.println("Health Difference: " + healthDifference(75, 120)); // 45

        // Test Part B
        System.out.println("Attack Damage: " + calculateDamage(10.0, 2)); // 22.5

        // Test Part C
        System.out.println("Distance: " + findDistance(0, 0, 3, 4)); // 5.0

        // Test Part D
        System.out.println("Random Loot: " + generateLoot(10, 50)); // random between 10–50
    }
}

GameStatsCalculator.main(null);

Health Difference: 45
Attack Damage: 22.5
Distance: 5.0
Random Loot: 27