Week 3 - Data Structures & Testing 

Collections

Generics

Enums

Stream APIs

Unit Testing with JUnit

Debugging in Java

Practice

Assignment

Back end Track

Week 3 Assignment

Task 1 - Pizza Order

We will build a small model for pizza ordering. An order holds a list of pizzas. Each pizza has a size and a list of toppings. The model can calculate the total price of an order and print a receipt.

Requirements

  1. Size enum where each value carries a base price in euros:
  2. Topping enum where each value carries a price:
  3. Pizza class:
  4. Order class:
  5. Main - create an order with at least three pizzas of different sizes and toppings, then print the receipt.

Expected output

=== Receipt ===
MEDIUM pizza with [CHEESE, MUSHROOMS] - €11.50
LARGE pizza with [PEPPERONI, OLIVES, CHEESE] - €16.00
SMALL pizza with [PINEAPPLE] - €7.50
---------------
Total: €35.00

Hint: enums can carry data

Task 2 - Generic Cache

Caching is the process of storing temporary copies of frequently accessed data in a fast, easy-to-reach location (the "cache"). For example, fetching something from the database once and storing it in the memory to fast access.

In this task, we will build a reusable in-memory cache. The class is generic, so the caller decides the value type when creating an instance. In addition, we will be covering our class with unit tests.

Requirements

Cache<T> - backed internally by a HashMap. Implement these methods:

Examples

Cache<String> stringCache = new Cache<String>();
stringCache.put("name", "HackYourFuture");
stringCache.get("name"); // -> "HackYourFuture"
stringCache.get("city"); // -> null

Cache<Integer> numberCache = new Cache<Integer>();
numberCache.put("c1", 12345);
numberCache.put("c2", 54321);
numberCache.size(); // -> 2
numberCache.remove("c1");
numberCache.get("c1"); // -> null

Submission

Follow the Assignment submission guide to learn how to submit the assignment


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❤️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.