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.
Size enum where each value carries a base price in euros:
SMALL → €6.00, MEDIUM → €9.00, LARGE → €12.00getBasePrice() to return the size price.Topping enum where each value carries a price:
CHEESE → €1.00, MUSHROOMS → €1.50, PEPPERONI → €2.00, OLIVES → €1.00, PINEAPPLE → €1.50getPrice() to return the topping price.Pizza class:
getTotalPrice() returning the size's base price plus all topping pricestoString() returning MEDIUM pizza with [CHEESE, MUSHROOMS] - €11.50Order class:
addPizza(Pizza pizza) - Adds a new pizza to the order.getTotalPrice() returning the sum of all pizza pricesprintReceipt() printing one line per pizza followed by a total lineMain - create an order with at least three pizzas of different sizes and toppings, then print the receipt.=== 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
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.
Cache<T> - backed internally by a HashMap. Implement these methods:
put(String key, T value) - Add a new item to the cachepublic T get(String key) - Fetches an item from the cache. The item may not be in the cache.T remove(String key) - Remove an item from the cache and return it.int size() - Returns the number of items in the cache.void clear() - Removes all items from the cacheString and Double . Call a few methods on those objects.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
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/*

Built with ❤️ by the HackYourFuture community · Thank you, contributors
Found a mistake or have a suggestion? Let us know in the feedback form.