Advertisement
Guest User

1. Съдомиялна (Dishwasher)

a guest
Jun 19th, 2019
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Dishwasher {
  4.   public static void main(String[] args) {
  5.    
  6.     Scanner scanner = new Scanner(System.in);
  7.    
  8.     int bottles = Integer.parseInt(scanner.nextLine());
  9.     int detergent = bottles * 750;
  10.     String command = scanner.nextLine();
  11.     int dishes = 0;
  12.     int pots = 0;
  13.     int utensilsCounter = 0;
  14.     int dishesCounter = 0;
  15.     int potsCounter = 0;
  16.     int neededDetergent = 0;
  17.     boolean ifDishes = false;
  18.     boolean ifPots = false;
  19.    
  20.     while (!command.equals("End")) {
  21.       int utensils = Integer.parseInt(command);
  22.       utensilsCounter++;
  23.    
  24.       if (utensilsCounter % 3 == 0) {
  25.         pots = utensils;
  26.         ifPots = true;
  27.         ifDishes = false;
  28.         detergent = detergent - (pots * 15);
  29.         potsCounter += pots;
  30.        
  31.       } else {
  32.         dishes = utensils;
  33.         ifDishes = true;
  34.         ifPots = false;
  35.         detergent = detergent - (dishes * 5);
  36.         dishesCounter += dishes;
  37.       }
  38.      
  39.       if ((ifDishes == true) && (ifPots = false)) {
  40.           if (detergent < (5 * dishes)) {
  41.             neededDetergent = Math.abs(detergent);
  42.             System.out.printf("Not enough detergent, %d ml. more necessary!", neededDetergent);
  43.             break;
  44.           }
  45.       } else if ((ifPots == true) && (ifDishes = false)) {
  46.           if (detergent < (15 * pots)) {
  47.             neededDetergent = Math.abs(detergent);
  48.             System.out.printf("Not enough detergent, %d ml. more necessary!", neededDetergent);
  49.             break;
  50.           }
  51.       }
  52.       command = scanner.nextLine();
  53.     }
  54.    
  55.     if (command.equals("End")) {
  56.         int leftOverDetergent = detergent;
  57.       System.out.printf("Detergent was enough!%n%d dishes and %d pots were washed.%nLeftover detergent %d ml.",
  58.                         dishesCounter, potsCounter, leftOverDetergent);
  59.     }  
  60.   }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement