Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 37 additions & 2 deletions src/coffeeMachine/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
package coffeeMachine;

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.print("Hello world!");
Scanner scanner = new Scanner(System.in);
System.out.println("Write how many ml of water the coffee machine has: ");
int water = scanner.nextInt();
System.out.println ("Write how many ml of milk the coffee machine has: ");
int milk = scanner.nextInt();
System.out.println ("Write how many grams of coffee beans the coffee machine has: ");
int coffee = scanner.nextInt();
System.out.println ("Write how many cups of coffee you will need: ");
int cups = scanner.nextInt();
int amount_w = water/200;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java, it is better to add one space between an operator and operands like water / 200;

int amount_m = milk/50;
int amount_c = coffee-cups /15;
int[] amount = {amount_w,amount_m,amount_c};
int min = amount[0];
for (int i=0;i<3;i++)
{
if (amount[i]<min)
{
min = amount[i];
}
}

if( min==cups) {
System.out.println("Yes, I can make that amount of coffee");
}
if( min<cups) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe is it better to use if-else construction here?

System.out.println("No, I can make only ");
System.out.print(min);
System.out.println(" cups of coffee");
}
if( min>cups) {
System.out.println("Yes, I can make that amount of coffee (and even ");
System.out.print(min-cups);
System.out.println(" more than that)");
}

}
}