|
| 1 | +/* |
| 2 | +A cookie recipe calls for the following ingredients: |
| 3 | +• 1.5 cups of sugar |
| 4 | +• 1 cup of butter |
| 5 | +• 2.75 cups of flour |
| 6 | +The recipe produces 48 cookies with these amounts of the ingredients. |
| 7 | +Write a program that asks the user how many cookies he or she wants to make, |
| 8 | +and then displays the number of cups of each ingredient needed for the specified number of cookies. |
| 9 | + */ |
| 10 | + |
| 11 | +package com.challenges; |
| 12 | + |
| 13 | +import java.util.Scanner; |
| 14 | + |
| 15 | +public class IngredientAdjuster { |
| 16 | + public static void main(String [] args) { |
| 17 | + |
| 18 | + // Declare Variables |
| 19 | + final int NO_OF_COOKIES = 48; |
| 20 | + final double CUPS_OF_SUGAR = 1.5; |
| 21 | + final double CUPS_OF_BUTTER = 1; |
| 22 | + final double CUPS_OF_FLOUR = 2.75; |
| 23 | + int noOfCookiesToMake; |
| 24 | + double cupsOfSugar; |
| 25 | + double cupsOfButter; |
| 26 | + double cupsOfFlour; |
| 27 | + |
| 28 | + Scanner scanner = new Scanner(System.in); |
| 29 | + |
| 30 | + System.out.println("Please enter the number of cookies to be made: "); |
| 31 | + noOfCookiesToMake = scanner.nextInt(); |
| 32 | + |
| 33 | + cupsOfSugar = ((float)CUPS_OF_SUGAR / NO_OF_COOKIES) * noOfCookiesToMake; |
| 34 | + cupsOfButter = ((float)CUPS_OF_BUTTER / NO_OF_COOKIES) * noOfCookiesToMake; |
| 35 | + cupsOfFlour = ((float) CUPS_OF_FLOUR / NO_OF_COOKIES) * noOfCookiesToMake; |
| 36 | + |
| 37 | + System.out.println("To make " + noOfCookiesToMake + " cookies,"); |
| 38 | + System.out.println("Cups of Sugar: " + cupsOfSugar); |
| 39 | + System.out.println("Cups of Butter: " + cupsOfButter); |
| 40 | + System.out.println("Cups of Flour: " + cupsOfFlour); |
| 41 | + } |
| 42 | +} |
0 commit comments