galinyotsev123

ProgBasicsExam28and29July2018-E02beerAndChips

Dec 28th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class E02beerAndChips {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String name = scanner.nextLine();
  8. double budjet = Double.parseDouble(scanner.nextLine());
  9. double beers = Double.parseDouble(scanner.nextLine()); // can be done with int beers = Integer.parseInt(scanner.nextLine());
  10. double chips = Double.parseDouble(scanner.nextLine()); // can be done with int chips = Integer.parseInt(scanner.nextLine());
  11.  
  12. double billBeers = beers * 1.20;
  13. double billChips = chips * (billBeers * 0.45);
  14. billChips = Math.ceil(billChips);
  15.  
  16. double totalBill = billBeers + billChips;
  17. //double diff = budjet - totalBill;
  18. //diff = Math.abs(diff);
  19.  
  20. if (totalBill <= budjet ) {
  21. System.out.printf("%s bought a snack and has %.2f leva left.",name, budjet-totalBill);
  22.  
  23. }
  24. else {
  25. System.out.printf("%s needs %.2f more leva!",name,totalBill-budjet );
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment