Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.text.DecimalFormat;
  3. import java.util.Scanner;
  4.  
  5. public class Ex01HungryGarfield {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         BigDecimal money = new BigDecimal(scanner.nextLine());
  9.         BigDecimal exchangeRate = new BigDecimal(scanner.nextLine());
  10.         BigDecimal pizzaPriceLv = new BigDecimal(scanner.nextLine());
  11.         BigDecimal lasagnaPriceLv = new BigDecimal(scanner.nextLine());
  12.         BigDecimal sandwichPriceLv = new BigDecimal(scanner.nextLine());
  13.         BigDecimal pizzaQuantity = new BigDecimal(scanner.nextLine());
  14.         BigDecimal lasagnaQuantity = new BigDecimal(scanner.nextLine());
  15.         BigDecimal sandwichQuantity = new BigDecimal(scanner.nextLine());
  16.  
  17.         BigDecimal totalCost = pizzaPriceLv.multiply(pizzaQuantity);
  18.         totalCost = totalCost.add(lasagnaPriceLv.multiply(lasagnaQuantity));
  19.         totalCost = totalCost.add(sandwichPriceLv.multiply(sandwichQuantity));
  20.         totalCost = totalCost.divide(exchangeRate, 2, BigDecimal.ROUND_HALF_UP);
  21.  
  22.         DecimalFormat df = new DecimalFormat("0.00");
  23.         BigDecimal moneyLeft = money.subtract(totalCost);
  24.  
  25.         if (moneyLeft.compareTo(BigDecimal.ZERO) >= 0d) {
  26.             System.out.printf("Garfield is well fed, John is awesome. Money left: $%s.%n", df.format(moneyLeft));
  27.         } else {
  28.             System.out.printf("Garfield is hungry. John is a badass. Money needed: $%s.%n", df.format(moneyLeft.abs()));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement