• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest May 13th, 2017 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.math.BigDecimal;
2. import java.text.DecimalFormat;
3. import java.util.Scanner;
4.
5. /**
6.  * https://judge.softuni.bg/Contests/Practice/Index/163#0
7.  */
8.
9. public class Ex01HungryGarfield {
10.     public static void main(String[] args) {
11.         Scanner scanner = new Scanner(System.in);
12.         BigDecimal money = new BigDecimal(scanner.nextLine());
13.         BigDecimal exchangeRate = new BigDecimal(scanner.nextLine());
14.         BigDecimal pizzaPriceLv = new BigDecimal(scanner.nextLine());
15.         BigDecimal lasagnaPriceLv = new BigDecimal(scanner.nextLine());
16.         BigDecimal sandwichPriceLv = new BigDecimal(scanner.nextLine());
17.         BigDecimal pizzaQuantity = new BigDecimal(scanner.nextLine());
18.         BigDecimal lasagnaQuantity = new BigDecimal(scanner.nextLine());
19.         BigDecimal sandwichQuantity = new BigDecimal(scanner.nextLine());
20.
21.         BigDecimal totalCost = pizzaPriceLv.multiply(pizzaQuantity);
24.         totalCost = totalCost.divide(exchangeRate, 2, BigDecimal.ROUND_HALF_UP);
25.
26.         DecimalFormat df = new DecimalFormat("0.00");
27.         BigDecimal moneyLeft = money.subtract(totalCost);
28.         if (moneyLeft.compareTo(BigDecimal.ZERO) >= 0) {
29.             System.out.printf("Garfield is well fed, John is awesome. Money left: \$%s.%n", df.format(moneyLeft));
30.         } else {
31.             System.out.printf("Garfield is hungry. John is a badass. Money needed: \$%s.%n", df.format(moneyLeft.abs()));
32.         }
33.     }
34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top