Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws IOException {
  7.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  8.  
  9.         String command = reader.readLine();
  10.         while (!"End".equals(command)){
  11.             if (!command.isEmpty()){
  12.                 String[] beer = command.split("\\s+");
  13.                 int beerBought = Integer.parseInt(beer[0]);
  14.                 int beerDrank = Integer.parseInt(beer[1]);
  15.  
  16.                 BeerCounter.BuyBeer(beerBought);
  17.                 BeerCounter.DrinkBeer(beerDrank);
  18.             }
  19.  
  20.             command = reader.readLine();
  21.         }
  22.  
  23.         System.out.printf("%d %d%n", BeerCounter.getBeerInStock(),BeerCounter.getBeerDrankCount());
  24.     }
  25. }
  26.  
  27. public class BeerCounter {
  28.     private static int beerInStock = 0;
  29.     private static int beerDrankCount = 0;
  30.  
  31.     public static void BuyBeer(int bottlesCount){
  32.         if (bottlesCount > 0)
  33.         beerInStock+=bottlesCount;
  34.     }
  35.  
  36.     public static void DrinkBeer(int bottlesCount){
  37.         if(beerInStock >= bottlesCount){
  38.             beerInStock-= bottlesCount;
  39.             beerDrankCount += bottlesCount;
  40.         }
  41.     }
  42.  
  43.     public static int getBeerInStock() {
  44.         return beerInStock;
  45.     }
  46.  
  47.     public static int getBeerDrankCount() {
  48.         return beerDrankCount;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement