Advertisement
yovkovbpfps

If else Beer And Chips

Apr 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BeerAndChips {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7.  
  8. String name = scanner.nextLine();
  9. double budget = Double.parseDouble(scanner.nextLine());
  10. int beers = Integer.parseInt(scanner.nextLine());
  11. int chips = Integer.parseInt(scanner.nextLine());
  12.  
  13.  
  14. double allBeerPrice = 1.20 * beers;
  15. double onePackageChips = allBeerPrice * 0.45;
  16. double allChipsPrice = Math.ceil(onePackageChips * chips);
  17. double totalSum = allBeerPrice + allChipsPrice;
  18. double value = budget - totalSum;
  19. double moreValue = totalSum - budget;
  20. if (totalSum <= budget){
  21. System.out.printf("%s bought a snack and has %.2f leva left.",name,value);
  22. }else{
  23. System.out.printf("%s needs %.2f more leva!",name,moreValue);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement