Daily Challenge #309 - Coffee Customization

dev.to staff - Nov 20 '20 - - Dev Community

You're an employee at a local cafe.

You can serve 3 coffee recipes:

  • Black = Black Coffee
  • Cubano = Cubano coffee + Brown sugar
  • Americano = Americano coffee + Milk with 0.5% fat

... and you can add a lot of extra sugar and milk in any coffee, for example:

  • Black coffee + Milk with 3.2% fat + Brown sugar
  • Cubano coffee + Brown sugar + Brown sugar + Cane sugar
  • Americano coffee + Milk with 3.2% fat + Cane sugar

With the following code provided for you, can you create a Coffee by implementing a CoffeeBuilder struct/class?

You can start from scratch or use the following code as a starting off point:

C++
struct Milk {
  float fat;
};

struct Sugar {
  std::string sort;
};

struct Coffee {
  std::string sort;
  std::vector<Milk> milk;
  std::vector<Sugar> sugar;
};
Enter fullscreen mode Exit fullscreen mode
Rust
#[derive(Debug)]
struct Coffee {
    sort: String,
    milk: Vec<Milk>,
    sugar: Vec<Sugar>,
}

#[derive(Debug)]
struct Milk {
    fat: f32,
}

#[derive(Debug)]
struct Sugar {
    sort: String,
}

struct CoffeeBuilder {
    sort: String,
    milk: Vec<Milk>,
    sugar: Vec<Sugar>,
}
Enter fullscreen mode Exit fullscreen mode

Tests

  1. A Black coffee with sugar and milk with 3.2% fat, please.
  2. A Cubano coffee, please.
  3. An Americano with two brown sugars, please.

Good luck!


This challenge comes from arkada38 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .