Advertisement
Spocoman

Beer and chips

Sep 1st, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String name = scanner.nextLine();
  7.  
  8.         double budget = Double.parseDouble(scanner.nextLine());
  9.         int beers = Integer.parseInt(scanner.nextLine()),
  10.                 chips = Integer.parseInt(scanner.nextLine());
  11.         double beerPrice = beers * 1.20,
  12.                 chipsPrice = chips * beerPrice * 0.45,
  13.                 sum = beerPrice + Math.ceil(chipsPrice);
  14.  
  15.         if (budget < sum) {
  16.             System.out.printf("%s needs %.2f more leva!\n", name, sum - budget);
  17.         } else {
  18.             System.out.printf("%s bought a snack and has %.2f leva left.\n", name, budget - sum);
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement