Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BeerAndChips {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String name = scanner.nextLine();
- double budget = Double.parseDouble(scanner.nextLine());
- int beers = Integer.parseInt(scanner.nextLine());
- int chips = Integer.parseInt(scanner.nextLine());
- double allBeerPrice = 1.20 * beers;
- double onePackageChips = allBeerPrice * 0.45;
- double allChipsPrice = Math.ceil(onePackageChips * chips);
- double totalSum = allBeerPrice + allChipsPrice;
- double value = budget - totalSum;
- double moreValue = totalSum - budget;
- if (totalSum <= budget){
- System.out.printf("%s bought a snack and has %.2f leva left.",name,value);
- }else{
- System.out.printf("%s needs %.2f more leva!",name,moreValue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement