Advertisement
YavorGrancharov

CaloriesCounter

Jun 4th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CaloriesCounter {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(console.nextLine());
  8.  
  9.         int sum = 0;
  10.  
  11.         int calories = 0;
  12.  
  13.         String[] ingredients = {
  14.                 "cheese",
  15.                 "tomato sauce",
  16.                 "salami",
  17.                 "pepper"
  18.         };
  19.  
  20.             for (int i = 1; i <= n; i++) {
  21.                 String ingredient = console.nextLine().toLowerCase();
  22.                 if (ingredient.length() >= 1 && ingredient.length() <= 50) {
  23.                     if (ingredient.equals(ingredients[0])) {
  24.                         calories += 500;
  25.                     } else if (ingredient.equals(ingredients[1])) {
  26.                         calories += 150;
  27.                     } else if (ingredient.equals(ingredients[2])) {
  28.                         calories += 600;
  29.                     } else if (ingredient.equals(ingredients[3])) {
  30.                         calories += 50;
  31.                     }
  32.                 }
  33.             }
  34.             System.out.println("Total calories: " + calories);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement