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