{"id":20391439,"url":"https://github.com/seycileli/coffeemachine","last_synced_at":"2026-02-09T13:06:19.471Z","repository":{"id":124683561,"uuid":"223632629","full_name":"seycileli/CoffeeMachine","owner":"seycileli","description":"Coffee Machine Simulator. This project is from Hyperskill.io, the project is completed in 3 different ways, the final source being more clean code.","archived":false,"fork":false,"pushed_at":"2020-11-05T07:21:39.000Z","size":62,"stargazers_count":6,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T06:22:09.577Z","etag":null,"topics":["cappuccino","coffee-beans","coffee-lovers","coffee-machine","coffeemaker","disposable-cups","espresso","java","latte","milk","money","simulation","user-simulator","water"],"latest_commit_sha":null,"homepage":"https://hyperskill.org/projects/33?goal=7","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seycileli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-23T18:11:26.000Z","updated_at":"2024-06-18T13:21:05.000Z","dependencies_parsed_at":"2023-09-25T00:58:18.607Z","dependency_job_id":null,"html_url":"https://github.com/seycileli/CoffeeMachine","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.08695652173913049,"last_synced_commit":"02e4ea98be4d68b87ab2aa3cb97e5168003a9106"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seycileli%2FCoffeeMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seycileli%2FCoffeeMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seycileli%2FCoffeeMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seycileli%2FCoffeeMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seycileli","download_url":"https://codeload.github.com/seycileli/CoffeeMachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248560470,"owners_count":21124661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cappuccino","coffee-beans","coffee-lovers","coffee-machine","coffeemaker","disposable-cups","espresso","java","latte","milk","money","simulation","user-simulator","water"],"created_at":"2024-11-15T03:32:59.183Z","updated_at":"2026-02-09T13:06:19.428Z","avatar_url":"https://github.com/seycileli.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoffeeMachine\n\nAbout:\n------\n\nWhat can be better than a cup of coffee during a break? \n\nA coffee that you don’t have to make yourself. It’s enough to press a couple of buttons on the machine and you get a cup of energy; but first, we should teach the machine how to do it. \n\nIn this project, you will work on programming a coffee-machine simulator. \n\nThe machine works with quite typical products: \n\n- Coffee, milk, sugar, and plastic cups\n\nIF it runs out of something, it shows a notification. \n\nThe machine can make three types of coffee: espresso, cappuccino, and latte. \n\nSince nothing’s for free, it also collects the money.\n\nResult\n------\n\nThis project allows you to get a taste of Java. An important part of Java are classes, and this is what you will practice here. \n\nTry yourself at working with loops and conditions and get more confident in Java programming.\n\nhttps://imgur.com/BuD259h\n\nStage #1: Hello, coffee!\n------------------------\n\nWrite a program that puts basic information on the screen: \nGive the machine a chance to tell the customers what it’s doing!\n\nDescription:\n\nLet's start with a program that makes you a coffee – virtual coffee, of course. \n\nBut in this project, you will implement functionality that simulates a real coffee machine. It can run out of milk, it can run out of coffee beans, it can make different varieties of coffee, and it can take the money for making a coffee.\n\nThe first version of the program just makes you a coffee. It prints to the standard output what it is doing as it makes a coffee.\n\nOutput example:\n---------------\n\nUsing the \"Hello, World!\" program, write the program that prints all lines as in the example below.\n\nStarting to make a coffee\n\nGrinding coffee beans\n\nBoiling water\n\nMixing boiled water with crushed coffee beans\n\nPouring coffee into the cup\n\nPouring some milk into the cup\n\nCoffee is ready!\n\nStage #2: Machines have needs\n-----------------------------\n\nProgram the machine to calculate the amount of ingredients it needs depending on how many people want some coffee.\n\nDescription:\n\nNow let's consider a case where you need a lot of coffee. Maybe, for example, you’re hosting a party with a lot of guests. The program should calculate how much water, coffee beans, and milk are necessary to make the specified amount of coffee. One cup of coffee made on this coffee machine contains 200 ml of water, 50 ml of milk, and 15 g of coffee beans.\n\nThe user should input the amount of coffee he needs, in cups, for all the guests.\n\nOf course, all this coffee is not needed right now, so at this stage, the coffee machine doesn’t actually make any coffee.\n\nOutput example\n---------------\n\nThe example below shows how your output might look.\n\nWrite how many cups of coffee you will need: 25\n\nFor 25 cups of coffee you will need:\n\n5000 ml of water\n\n1250 ml of milk\n\n375 g of coffee beans\n\nOR;\n\nWrite how many cups of coffee you will need: 125\n\nFor 125 cups of coffee you will need:\n\n25000 ml of water\n\n6250 ml of milk\n\n1875 g of coffee beans\n\nStage #3: Enough coffee for everyone\n------------------------------------\n\nWorking with conditions, program the machine to estimate how many creamy coffees it can make based on the amount of ingredients we enter.\n\nDescription\n\nA real coffee machine never has an infinite supply of water, milk, or coffee beans. And if you input a really big number, it’s almost certain that a real coffee machine wouldn't have the supplies needed to make all that coffee.\n\nIn this stage, you need to improve the previous program. Now you need to input amounts of water, milk, and coffee beans that your coffee machine has at the moment.\n\nIf the coffee machine has enough supplies to make the specified amount of coffee, the program should print \"Yes, I can make that amount of coffee\". If the coffee machine can make more than that, the program should output \"Yes, I can make that amount of coffee (and even N more than that)\", where N is the number of additional cups of coffee that the coffee machine can make. If the amount of resources is not enough to make the specified amount of coffee, the program should output \"No, I can make only N cup(s) of coffee\".\n\nLike in the previous stage, the coffee machine needs 200 ml of water, 50 ml of milk, and 15 g of coffee beans to make one cup of coffee.\n\nOutput example\n--------------\n\nThe program should firstly request for water, then milk, then beans, then amount of cups.\n\nWrite how many ml of water the coffee machine has: 300\n\nWrite how many ml of milk the coffee machine has: 65\n\nWrite how many grams of coffee beans the coffee machine has: 100\n\nWrite how many cups of coffee you will need: 1\n\nYes, I can make that amount of coffee\n\nOR;\n\nWrite how many ml of water the coffee machine has: 500\n\nWrite how many ml of milk the coffee machine has: 250\n\nWrite how many grams of coffee beans the coffee machine has: 200\n\nWrite how many cups of coffee you will need: 10\n\nNo, I can make only 2 cup(s) of coffee\n\nOR;\n\nWrite how many ml of water the coffee machine has: 1550\n\nWrite how many ml of milk the coffee machine has: 299\n\nWrite how many grams of coffee beans the coffee machine has: 300\n\nWrite how many cups of coffee you will need: 3\n\nYes, I can make that amount of coffee (and even 2 more than that)\n\nOR;\n\nWrite how many ml of water the coffee machine has: 0\n\nWrite how many ml of milk the coffee machine has: 0\n\nWrite how many grams of coffee beans the coffee machine has: 0\n\nWrite how many cups of coffee you will need: 1\n\nNo, I can make only 0 cup(s) of coffee\n\nOR;\n\nWrite how many ml of water the coffee machine has: 0\n\nWrite how many ml of milk the coffee machine has: 0\n\nWrite how many grams of coffee beans the coffee machine has: 0\n\nWrite how many cups of coffee you will need: 0\n\nYes, I can make that amount of coffee\n\nOR;\n\nWrite how many ml of water the coffee machine has: 200\n\nWrite how many ml of milk the coffee machine has: 50\n\nWrite how many grams of coffee beans the coffee machine has: 15\n\nWrite how many cups of coffee you will need: 0\n\nYes, I can make that amount of coffee (and even 1 more than that)\n\nStage #4: Action!\n------------------\n\nUpgrade your knowledge of methods - set the machine to perform three basic actions: collect the money, renew the supplies, and serve the coffee.\n\nDescription:\n\nLet's simulate an actual coffee machine. It has a limited supply of water, milk, coffee beans, and disposable cups. Also, it counts how much money it gets for selling coffee. The coffee machine has several options: first, it needs to be able to sell coffee. It can make different varieties of coffee: espresso, latte, and cappuccino. Of course, each variety requires a different amount of supplies, except that all of them requires only one disposable cup. Second, the coffee machine should be able to get replenished by a special worker. Third, another special worker should be able to take money from the coffee machine.\n\nWrite the program that can do one of these actions at a time. It reads one line from standard input, which can be \"buy\", \"fill\", \"take\". If you want to buy some coffee, input \"buy\". If you are a special worker and you think that it is time to fill out all the supplies for the coffee machine, input \"fill\". If you are another special worker and it is time to take the money from the coffee machine, input \"take\".\n\nIf the user writes \"buy\" then he must choose one of three varieties of coffee that the coffee machine can make: espresso, latte, or cappuccino.\n\nFor the espresso, the coffee machine needs 250 ml of water and 16 g of coffee beans. It costs $4.\nFor the latte, the coffee machine needs 350 ml of water, 75 ml of milk, and 20 g of coffee beans. It costs $7.\nAnd for the cappuccino, the coffee machine needs 200 ml of water, 100 ml of milk, and 12 g of coffee. It costs $6.\nIf the user writes \"fill\", the program should ask him how much water, milk, coffee beans and how many disposable cups he wants to add into the coffee machine.\n\nIf the user writes \"take\" the program should give him all the money that it earned from selling coffee.\n\nAt the moment, the coffee machine has $550, 1200 ml of water, 540 ml of milk, 120 g of coffee beans, and 9 disposable cups.\n\nWrite the program that prints the coffee machine’s state, processes one query from the user, and also prints the coffee machine’s state after that. Try to use methods to implement every action that the coffee machine can do.\n\nOutput example\n---------------\n\nAn espresso should be as number 1 in the list, a latte as number 2 and a cappuccino as number 3.\nOptions also should be named as \"buy\", \"fill\", \"take\".\n\nThe coffee machine has:\n\n1200 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n550 of money\n\nWrite action (buy, fill, take): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino: 3\n\nThe coffee machine has:\n\n1000 of water\n\n440 of milk\n\n108 of coffee beans\n\n8 of disposable cups\n\n556 of money\n\nor,\n\n \n\nThe coffee machine has:\n\n1200 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n550 of money\n\nWrite action (buy, fill, take): fill\n\nWrite how many ml of water do you want to add: 2000\n\nWrite how many ml of milk do you want to add: 500\n\nWrite how many grams of coffee beans do you want to add: 100\n\nWrite how many disposable cups of coffee do you want to add: 10\n\nThe coffee machine has:\n\n3200 of water\n\n1040 of milk\n\n220 of coffee beans\n\n19 of disposable cups\n\n550 of money\n\nOR;\n\nThe coffee machine has:\n\n1200 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n550 of money\n\nWrite action (buy, fill, take): take\n\nI gave you $550\n\nThe coffee machine has:\n\n1200 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n0 of money\n\nStage #5: On a coffee loop\n--------------------------\n\nProgram the machine to display on the screen the amount of supplies left. Set the main loop: now the menu keeps updating until you press exit.\n\nDescription\n\nBut just one action isn’t interesting. Let's improve the program so it can do multiple actions, one after another. The program should repeatedly ask what the user wants to do. If the user types \"buy\", \"fill\" or \"take\", then just do what the program did in the previous step. However, if the user wants to switch off the coffee machine, he should type \"exit\". Then the program should terminate. Also, when the user types \"remaining\", the program should output all the resources that the coffee machine has.\n\nAlso, do not forget that you can be out of resources for making coffee. If the coffee machine doesn’t have enough resources to make coffee, the program should output a message that says it can't make a cup of coffee.\n\nAnd the last improvement to the program at this step—if the user types \"buy\" to buy a cup of coffee and then changes his mind, he should be able to type \"back\" to return into the main cycle.\n\nRemember, that:\n\nFor the espresso, the coffee machine needs 250 ml of water and 16 g of coffee beans. It costs $4.\nFor the latte, the coffee machine needs 350 ml of water, 75 ml of milk, and 20 g of coffee beans. It costs $7.\nAnd for the cappuccino, the coffee machine needs 200 ml of water, 100 ml of milk, and 12 g of coffee. It costs $6.\n\nOutput example:\n\nYour coffee machine should have the same initial resources as in the example (400 ml of water, 540 ml of milk, 120 g of coffee beans, 9 disposable cups, $550 in cash).\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n400 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n$550 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nI have enough resources, making you a coffee!\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n50 of water\n\n465 of milk\n\n100 of coffee beans\n\n8 of disposable cups\n\n$557 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nSorry, not enough water!\n\nWrite action (buy, fill, take, remaining, exit): fill\n\nWrite how many ml of water do you want to add: 1000\n\nWrite how many ml of milk do you want to add: 0\n\nWrite how many grams of coffee beans do you want to add: 0\n\nWrite how many disposable cups of coffee do you want to add: 0\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n1050 of water\n\n465 of milk\n\n100 of coffee beans\n\n8 of disposable cups\n\n$557 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nI have enough resources, making you a coffee!\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n700 of water\n\n390 of milk\n\n80 of coffee beans\n\n7 of disposable cups\n\n$564 of money\n\nWrite action (buy, fill, take, remaining, exit): take\n\nI gave you $564 \n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n700 of water\n\n390 of milk\n\n80 of coffee beans\n\n7 of disposable cups\n\n0 of money\n\nWrite action (buy, fill, take, remaining, exit): exit\n\nStage #6: Brush your code\n-------------------------\n\nTime for some final touch-ups: structure the code so that it runs smoothly.\n\nDescription\n\nLet's redesign our program and write a class that represents the coffee machine. The class should have a method that takes a string as input. Every time the user inputs a line (a string) to the console, the program invokes this method with one argument: the line that user input to the console. This system simulates pretty accurately how real-world electronic devices work. External components (like buttons on the coffee machine or tapping on the screen) generate events that pass into the single interface of the program.\n\nThe class should not use system input at all; it only should handle input that comes to it via this method and its string argument.\n\nThe first problem that comes to mind: how to write that method in a way that it represents all that coffee machine can do? If the user inputs a single number, how can the method determine what that number is: a variant of coffee chosen by the user or the number of the disposable cups that a special worker added into the coffee machine?\n\nThe right solution to this problem is to store the current state of the machine. The coffee machine has several states it can be in. For example, the state could be \"choosing an action\" or \"choosing a variant of coffee\". Every time the user inputs something and a program passes that line to the method, the program determines how to interpret this line using the information about the current state. After processing this line, the state of the coffee machine can be changed or can stay the same. The most efficient way of handling states is using an enum with all predefined states.\n\nRemember, that:\n\nFor the espresso, the coffee machine needs 250 ml of water and 16 g of coffee beans. It costs $4.\nFor the latte, the coffee machine needs 350 ml of water, 75 ml of milk, and 20 g of coffee beans. It costs $7.\nAnd for the cappuccino, the coffee machine needs 200 ml of water, 100 ml of milk, and 12 g of coffee. It costs $6.\n\nOutput example:\n----------------\n\nYour coffee machine should have the same initial resources as in the example (400 ml of water, 540 ml of milk, 120 g of coffee beans, 9 disposable cups, $550 in cash).\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n400 of water\n\n540 of milk\n\n120 of coffee beans\n\n9 of disposable cups\n\n$550 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nI have enough resources, making you a coffee!\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n50 of water\n\n465 of milk\n\n100 of coffee beans\n\n8 of disposable cups\n\n$557 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nSorry, not enough water! \n\nWrite action (buy, fill, take, remaining, exit): fill\n\nWrite how many ml of water do you want to add: 1000\n\nWrite how many ml of milk do you want to add: 0\n\nWrite how many grams of coffee beans do you want to add: 0\n\nWrite how many disposable cups of coffee do you want to add: 0\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n1050 of water\n\n465 of milk\n\n100 of coffee beans\n\n8 of disposable cups\n\n$557 of money\n\nWrite action (buy, fill, take, remaining, exit): buy\n\nWhat do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: 2\n\nI have enough resources, making you a coffee!\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n700 of water\n\n390 of milk\n\n80 of coffee beans\n\n7 of disposable cups\n\n$564 of money\n\nWrite action (buy, fill, take, remaining, exit): take\n\nI gave you $564\n\nWrite action (buy, fill, take, remaining, exit): remaining\n\nThe coffee machine has:\n\n700 of water\n\n390 of milk\n\n80 of coffee beans\n\n7 of disposable cups\n\n$0 of money\n\nWrite action (buy, fill, take, remaining, exit): exit\n\nCredit: https://hyperskill.org/projects/33?goal=7\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseycileli%2Fcoffeemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseycileli%2Fcoffeemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseycileli%2Fcoffeemachine/lists"}