Advertisement
ilianrusev

Technology Fundamentals Mid Exam - 10 March 2019 Group 2 - 2

Apr 15th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         List<Integer> cellsPuttedOut = new ArrayList<>();
  14.         int totalFire = 0;
  15.         double effort = 0.00;
  16.         int value = 0;
  17.         String type = "";
  18.  
  19.         String input = scanner.nextLine();
  20.         int water = Integer.parseInt(scanner.nextLine());
  21.  
  22.         String[] firstSplit = input.split("[#]+");
  23.  
  24.         System.out.println();
  25.  
  26.         for (int i = 0; i < firstSplit.length; i++) {
  27.  
  28.             String[] typeAndValue = firstSplit[i].split("[ = ]+");
  29.             type = typeAndValue[0];
  30.             value = Integer.parseInt(typeAndValue[1]);
  31.  
  32.             if (water <= 0 )
  33.             {
  34.                 break;
  35.             }
  36.             if (water < value){
  37.                 continue;
  38.             }
  39.  
  40.  
  41.             if (type.equals("High" ) && (value >=81 && value <= 125)){
  42.  
  43.                         water -= value;
  44.                         totalFire += value;
  45.                         effort = effort + (value * 0.25);
  46.                         cellsPuttedOut.add(value);
  47.  
  48.             }
  49.             if (type.equals("Medium") && (value >=51 && value <= 80)){
  50.  
  51.                         water -= value;
  52.                         totalFire += value;
  53.                         effort = effort + (value * 0.25);
  54.                         cellsPuttedOut.add(value);
  55.  
  56.             }
  57.             if (type.equals("Low") && (value >=1 && value <= 50)){
  58.  
  59.                         water -= value;
  60.                         totalFire += value;
  61.                         effort = effort + (value * 0.25);
  62.                         cellsPuttedOut.add(value);
  63.  
  64.             }
  65.         }
  66.  
  67.         System.out.println("Cells:");
  68.         for (int i = 0; i < cellsPuttedOut.size(); i++) {
  69.             System.out.printf("- %d\n",cellsPuttedOut.get(i));
  70.         }
  71.         System.out.printf("Effort: %.2f\n",effort);
  72.         System.out.printf("Total Fire: %d",totalFire);
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement