Option B:
public class BankAccountSimulation {
public static void main(String[] args) {
double balance = 5000.0;
int transactions = 0;
double monthlyFee = 10.0;
double interestRate = 0.02;
for (int month = 1; month <= 12; month++) {
System.out.println("Month " + month + ":");
balance += 3000;
transactions++;
System.out.println(" + Salary added: $3000.00");
balance -= 1200;
transactions++;
System.out.println(" - Rent paid: $1200.00");
balance -= monthlyFee;
transactions++;
System.out.println(" - Monthly fee: $" + monthlyFee);
balance *= (1 + interestRate);
System.out.printf(" * Interest applied (%.0f%%): $%.2f%n", interestRate * 100, balance);
System.out.printf("End of month balance: $%.2f%n", balance);
System.out.println("----------------------------");
}
double averageMonthlySpending = (12 * (1200 + monthlyFee));
averageMonthlySpending /= 12;
int tier = transactions % 5;
System.out.println("=== YEARLY SUMMARY ===");
System.out.printf("Final Balance: $%.2f%n", balance);
System.out.println("Total Transactions: " + transactions);
System.out.printf("Average Monthly Spending: $%.2f%n", averageMonthlySpending);
System.out.println("Account Tier (based on transactions): " + tier);
}
}
Popcorn Hack 1
public class Example {
public static void main(String[] args) {
int score = 100;
double average = 85.5;
score += 50; // score = 150
score -= 25; // score = 125
score *= 2; // score = 250
score /= 5; // score = 50 (integer division)
score %= 15; // score = 5 (50 % 15)
average += 4.5; // average = 90.0
int count = 0;
count++; // count = 1
count--; // count = 0
System.out.println(count);
}
}
Example.main(null);
Popcorn Hack 2
public class PopcornHack2 {
public static void main(String[] args) {
int score = 100; // Starting score
System.out.println("Starting score: " + score);
// Deduct points for a wrong answer
score -= 20; // same as score = score - 20
System.out.println("After wrong answer (-20): " + score);
// Double the score with a power-up
score *= 2; // same as score = score * 2
System.out.println("After power-up (*2): " + score);
// Find remainder after dividing by 7
score %= 7; // same as score = score % 7
System.out.println("After dividing by 7 (remainder): " + score);
// Bonus round: gain a few points
score += 5; // same as score = score + 5
System.out.println("After bonus (+5): " + score);
// End of simulation
System.out.println("=== FINAL SCORE: " + score + " ===");
}
}
PopcornHack2.main(null);
Starting score: 100
After wrong answer (-20): 80
After power-up (*2): 160
After dividing by 7 (remainder): 6
After bonus (+5): 11
=== FINAL SCORE: 11 ===