Popcorn Hack 1
public class PowerCalculator {
public static void main(String[] args) {
int basePower = 100;
int level = 10; // You can change this or ask user input
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);
}
}
PowerCalculator.main(null);
Level: 10
Base Power: 100
Final Power: 619.17
popcorn Hack 2
public class LootDropSim {
public static void main(String[] args) {
System.out.println("Loot Drop!");
// Generate random rarity number (1–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() * 21) + 10; // 10–30
} else if (rarityRoll <= 85) {
rarity = "RARE";
goldValue = (int)(Math.random() * 40) + 31; // 31–70
} else {
rarity = "LEGENDARY";
goldValue = (int)(Math.random() * 30) + 71; // 71–100
}
System.out.println("You got: " + rarity + " item");
System.out.println("Gold Value: " + goldValue);
}
}
LootDropSim.main(null);
Loot Drop!
Rarity Roll: 53
You got: COMMON item
Gold Value: 29
MCQ
//QUESTION 1
int n = (int) Math.pow(2, 3.0 / 2);
System.out.println(n);
2
Answer: A
//QUESTION 2
int r = (int) (Math.random() * 6) + 5;
System.out.println(r);
8
Answer: A
//QUESTION 3
long a = Math.round(-3.5);
double b = Math.floor(-3.1);
double c = Math.ceil(-3.1);
int x = (int) a + (int) b + (int) c;
System.out.println(x);
-10
Answer: A
QUESTION 4
Answer: A
//QUESTION 5
int a = (int) Math.sqrt(26);
int b = (int) Math.sqrt(26);
System.out.println(a * b);
25
Answer: B
Homework Hacks
//PART A
public class HealthDifferenceCalculator {
public static int healthDifference(int player1Health, int player2Health) {
return Math.abs(player1Health - player2Health);
}
public static void main(String[] args) {
System.out.println("=== Health Difference Calculator ===");
System.out.println("Result 1: " + healthDifference(75, 120)); // 45
System.out.println("Result 2: " + healthDifference(100, 80)); // 20
System.out.println("Result 3: " + healthDifference(50, 50)); // 0
}
}
HealthDifferenceCalculator.main(null);
=== Health Difference Calculator ===
Result 1: 45
Result 2: 20
Result 3: 0
//PART B
public class AttackDamageCalculator {
public static double calculateDamage(double baseDamage, double powerLevel) {
return baseDamage * Math.pow(1.5, powerLevel);
}
public static void main(String[] args) {
System.out.println("=== Attack Damage Calculator ===");
System.out.println("Result 1: " + calculateDamage(10.0, 2)); // 22.5
System.out.println("Result 2: " + calculateDamage(15.0, 3)); // 50.625
}
}
AttackDamageCalculator.main(null);
=== Attack Damage Calculator ===
Result 1: 22.5
Result 2: 50.625
//PART C
public class DistanceDetector {
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));
}
public static void main(String[] args) {
System.out.println("=== Distance Detector ===");
System.out.println("Result 1: " + findDistance(0, 0, 3, 4)); // 5.0
System.out.println("Result 2: " + findDistance(1, 1, 4, 5)); // 5.0
}
}
DistanceDetector.main(null);
=== Distance Detector ===
Result 1: 5.0
Result 2: 5.0
public class RandomLootGenerator {
public static int generateLoot(int minValue, int maxValue) {
return (int)(Math.random() * (maxValue - minValue + 1)) + minValue;
}
public static void main(String[] args) {
System.out.println("=== Random Loot Generator ===");
System.out.println("Random Loot (10–50): " + generateLoot(10, 50));
System.out.println("Random Loot (1–6): " + generateLoot(1, 6)); // dice roll
System.out.println("Random Loot (100–100): " + generateLoot(100, 100)); // always 100
}
}
RandomLootGenerator.main(null);
=== Random Loot Generator ===
Random Loot (10–50): 17
Random Loot (1–6): 5
Random Loot (100–100): 100