Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package Cookies;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Cookies {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. int cookiesInABag = 40;
  10. int servingInABag = 10;
  11. int servingCalories = 300;
  12.  
  13. Scanner s = new Scanner(System.in);
  14.  
  15. System.out.print("Enter your name: ");
  16. String name = s.nextLine();
  17.  
  18. // User enters number of cookies eaten
  19. System.out.print("How many cookies did you eat? ");
  20. int numCookies = s.nextInt();
  21.  
  22.  
  23. // output calories consumed
  24. int servingSize = cookiesInABag / servingInABag;
  25. float userServings = (float)numCookies / (float)servingSize;
  26. float userCalories = userServings * servingCalories;
  27.  
  28. System.out.println(
  29. name + ", you ate " +
  30. userCalories + "calories"
  31. );
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement