Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String command = reader.readLine();
- while (!"End".equals(command)){
- if (!command.isEmpty()){
- String[] beer = command.split("\\s+");
- int beerBought = Integer.parseInt(beer[0]);
- int beerDrank = Integer.parseInt(beer[1]);
- BeerCounter.BuyBeer(beerBought);
- BeerCounter.DrinkBeer(beerDrank);
- }
- command = reader.readLine();
- }
- System.out.printf("%d %d%n", BeerCounter.getBeerInStock(),BeerCounter.getBeerDrankCount());
- }
- }
- public class BeerCounter {
- private static int beerInStock = 0;
- private static int beerDrankCount = 0;
- public static void BuyBeer(int bottlesCount){
- if (bottlesCount > 0)
- beerInStock+=bottlesCount;
- }
- public static void DrinkBeer(int bottlesCount){
- if(beerInStock >= bottlesCount){
- beerInStock-= bottlesCount;
- beerDrankCount += bottlesCount;
- }
- }
- public static int getBeerInStock() {
- return beerInStock;
- }
- public static int getBeerDrankCount() {
- return beerDrankCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement