Advertisement
meteor4o

JF-MidExam-10March-Group2-02.SeizeTheFire

Jun 28th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class SeizeTheFire {
  10.     public static void main(String[] args) {
  11.         Scanner sc = new Scanner(System.in);
  12.  
  13.         List<String> cells = Arrays.stream(sc.nextLine().split("\\#+"))
  14.                 .collect(Collectors.toList());
  15.         List<Integer> cellsPutOut = new ArrayList<>();
  16.  
  17.         int water = Integer.parseInt(sc.nextLine());
  18.         double totalEffort = 0.0;
  19.         int totalFire = 0;
  20.  
  21.         while (water > 0) {
  22.             for (int i = 0; i < cells.size(); i++) {
  23.                 String[] fireCell = cells.get(i).split(" = ");
  24.  
  25.                 int fireCellValue = Integer.parseInt(fireCell[1]);
  26.                 if (fireCell[0].equals("High") && fireCellValue >= 81 && fireCellValue <= 125 && water >= fireCellValue) {
  27.  
  28.                         totalEffort += fireCellValue * 0.25;
  29.                         totalFire += fireCellValue;
  30.                         cellsPutOut.add(fireCellValue);
  31.                         water -= fireCellValue;
  32.  
  33.                 } else if (fireCell[0].equals("Medium") && fireCellValue >= 51 && fireCellValue <= 80 && water >= fireCellValue) {
  34.  
  35.                         totalEffort += fireCellValue * 0.25;
  36.                         totalFire += fireCellValue;
  37.                         cellsPutOut.add(fireCellValue);
  38.                         water -= fireCellValue;
  39.  
  40.                 } else if (fireCell[0].equals("Low") && fireCellValue >= 1 && fireCellValue <= 50 && water >= fireCellValue) {
  41.  
  42.                         totalEffort += fireCellValue * 0.25;
  43.                         totalFire += fireCellValue;
  44.                         cellsPutOut.add(fireCellValue);
  45.                         water -= fireCellValue;
  46.                     }
  47.             }
  48.             break;
  49.         }
  50.         System.out.println("Cells: ");
  51.  
  52.         for(int cell : cellsPutOut) {
  53.             System.out.println(" - " + cell);
  54.         }
  55.         System.out.printf("Effort: %.2f%n", totalEffort);
  56.         System.out.println("Total Fire: " + totalFire);
  57.  
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement