Lesson 1.6
CSA Unit 1.6 — Assignment Statements and Input
Popcorn Hack #1
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++;
// Boss battle: double the current score
playerScore *= 2;
// Healing potion restores health to 80% of current
playerHealth *= 4;
playerHealth /= 5; // integer math: equivalent to 80% of current health
68
Popcorn Hack #2
// Initial account setup
double balance = 1500.00; // Current bank balance
int transactions = 0; // Number of transactions made this month
double monthlyFee = 12.50; // Bank maintenance fee
double interestRate = 1.02; // 2% interest multiplier
System.out.println("=== Bank Account Manager ===");
System.out.println("Starting balance: $" + balance);
System.out.println("---------------------------------------");
// Add monthly salary deposit
balance += 3000.00;
transactions++;
System.out.println("Added monthly salary. Balance: $" + balance);
// Subtract rent payment
balance -= 1200.00;
transactions++;
System.out.println("Paid rent. Balance: $" + balance);
// Apply monthly maintenance fee
balance -= monthlyFee;
transactions++;
System.out.println("Applied monthly fee. Balance: $" + balance);
// Apply 2% interest on remaining balance
balance *= interestRate;
System.out.println("Applied monthly interest. Balance: $" + balance);
// Average spending per transaction (rough estimate)
double averageTransaction = balance / transactions;
System.out.println("Average balance per transaction: $" + averageTransaction);
// Check account tier (remainder when divided by 5)
int tier = (int) balance % 5;
System.out.println("Account tier check (balance % 5): " + tier);
System.out.println("---------------------------------------");
System.out.println("End of month summary:");
System.out.println("Final Balance: $" + balance);
System.out.println("Transactions this month: " + transactions);
System.out.println("Average transaction balance: $" + averageTransaction);
System.out.println("=======================================");
=== Bank Account Manager ===
Starting balance: $1500.0
---------------------------------------
Added monthly salary. Balance: $4500.0
Paid rent. Balance: $3300.0
Applied monthly fee. Balance: $3287.5
Applied monthly interest. Balance: $3353.25
Average balance per transaction: $1117.75
Account tier check (balance % 5): 3
---------------------------------------
End of month summary:
Final Balance: $3353.25
Transactions this month: 3
Average transaction balance: $1117.75
=======================================