For each of the 6 coffee cups I buy, I get a 7th cup free. In total, I get 7 cups.

Knowing that I paid for `cups`

cups, compute and print the total number of cups I would get (number of cups I paid for + number of cups I got for free).

**Example:**

For example, if `cups`

was `12`

, the answer would be `14`

.

Why? Because I paid for 12 cups and I got 2 for free, which is a total of 14 cups.

In this lesson, we will explore a common promotional scenario where you get a free item after purchasing a certain number of items. Specifically, for every 6 coffee cups you buy, you get an additional cup for free. This type of problem is significant in programming as it involves basic arithmetic operations and conditional logic, which are fundamental in many real-world applications.

Such scenarios are common in retail promotions, loyalty programs, and bulk purchasing discounts. Understanding how to compute the total number of items received, including free items, is essential for both consumers and businesses to evaluate the benefits of such promotions.

Before diving into the solution, let's break down the problem:

- For every 6 cups you buy, you get 1 cup free.
- If you buy
`n`

cups, you need to determine how many free cups you get. - The total number of cups is the sum of the cups you paid for and the free cups.

For example, if you buy 12 cups, you get 2 free cups (one for each set of 6 cups), making a total of 14 cups.

To solve this problem, we need to use basic arithmetic operations:

- Division to determine how many sets of 6 cups you have.
- Addition to compute the total number of cups.

The logical flow is straightforward:

- Calculate the number of free cups by dividing the number of paid cups by 6.
- Add the number of free cups to the number of paid cups to get the total number of cups.

Let's look at a few examples to understand the concept better:

- If you buy 6 cups, you get 1 free cup, so the total is 7 cups.
- If you buy 12 cups, you get 2 free cups, so the total is 14 cups.
- If you buy 15 cups, you get 2 free cups (since 15 divided by 6 is 2 with a remainder), so the total is 17 cups.

Common mistakes to avoid:

- Forgetting to add the free cups to the total.
- Incorrectly calculating the number of free cups.

Best practices:

- Use integer division to calculate the number of free cups.
- Ensure your code is clear and well-commented.

For more advanced scenarios, consider cases where the promotion rules change, such as getting a free cup for every 5 cups bought. The logic remains similar, but the divisor changes.

Here is a Java implementation of the solution:

```
public class FreeCoffeeCups {
public static void main(String[] args) {
int cups = 12; // Example input
int totalCups = calculateTotalCups(cups);
System.out.println("Total cups: " + totalCups);
}
/**
* This method calculates the total number of cups including free cups.
* @param cups The number of cups paid for.
* @return The total number of cups including free cups.
*/
public static int calculateTotalCups(int cups) {
// Calculate the number of free cups
int freeCups = cups / 6;
// Calculate the total number of cups
return cups + freeCups;
}
}
```

To debug and test the code:

- Test with different values of
`cups`

to ensure the logic is correct. - Use print statements to verify intermediate values like the number of free cups.

Example test cases:

- Input: 6, Expected Output: 7
- Input: 12, Expected Output: 14
- Input: 15, Expected Output: 17

When approaching similar problems:

- Break down the problem into smaller parts.
- Use simple arithmetic operations to solve each part.
- Combine the results to get the final answer.

Practice with different scenarios to improve your problem-solving skills.

In this lesson, we covered how to calculate the total number of coffee cups received, including free cups, based on a promotional offer. We discussed the basic concepts, provided examples, and implemented a solution in Java. Understanding such problems is essential for handling real-world scenarios involving promotions and discounts.

Keep practicing and exploring more complex scenarios to enhance your programming skills.

For further reading and practice: