Compound Assignment Operators HW
For the thinkers group. 1.6.
int playerScore = 1000;
int playerHealth = 100;
int enemiesDefeated = 0;
// Player defeats an enemy worth 250 points
playerScore += 250;
// Player takes 15 damage
playerHealth -= 15;
// Enemy count goes up
enemiesDefeated += 1;
// Boss battle: double the current score!
playerScore *= 2;
// Healing potion restores health to 80% of current
playerHealth *= 4;
playerHealth /= 5; // 4/5 = 0.8, but we need integer math
int score = 100;
// Deduct points for a wrong answer
score -= 20;
System.out.println("After deduction: " + score);
// Double the score with a power-up
score *= 2;
System.out.println("After power-up: " + score);
// Find remainder after dividing by 7
score %= 7;
System.out.println("After finding remainder: " + score);
int totalCalories = 0;
int workoutDays = 0;
int stepCount = 0;
int weightGoal = 10; // Example: lose 10 kg
// Add calories from meals
totalCalories += 600;
// Burn calories from exercise
totalCalories -= 300;
// Increment workout days
workoutDays += 1;
// Double steps from an active day
stepCount += 5000; // Example: initial steps
stepCount *= 2;
// Calculate average daily steps (assuming 7 days in a week)
int averageSteps = stepCount / 7;
// Track weekly goal progress
int progress = weightGoal;
progress %= 7;
System.out.println("Total Calories: " + totalCalories);
System.out.println("Workout Days: " + workoutDays);
System.out.println("Step Count: " + stepCount);
System.out.println("Average Daily Steps: " + averageSteps);
System.out.println("Weekly Goal Progress: " + progress);