Advertisement
damesova

Drum Set [Mimi]

Feb 25th, 2019
210
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.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class _05_DrumSet {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         double savings = Double.parseDouble(scanner.nextLine());
  9.         //Here we put the initial values of drums's quality:
  10.         List<Integer> initialSet = Arrays.stream(scanner.nextLine()
  11.                 .split("\\s+"))
  12.                 .map(Integer::parseInt)
  13.                 .collect(Collectors.toList());
  14.         //Here we change the values through the usage:
  15.         List<Integer> drumSet = new ArrayList<>();
  16.         drumSet.addAll(initialSet);
  17.  
  18.  
  19.         String input = "";
  20.         int counter = 0;
  21.         while (true) {
  22.             input = scanner.nextLine();
  23.             if (input.equals("Hit it again, Gabsy!")) {
  24.  
  25.                 for (Integer integer : drumSet) {
  26.                     System.out.print(integer + " ");
  27.                 }
  28.                 System.out.println();
  29.                 System.out.printf("Gabsy has %.2flv.%n", savings);
  30.                 break;
  31.             }
  32.             int hitPower = Integer.parseInt(input);
  33.  
  34.             //While hitting the drums, decreasing the quality:
  35.             for (int i = 0; i < drumSet.size(); i++) {
  36.                 if (drumSet.get(i) > hitPower) {
  37.                     drumSet.set(i, drumSet.get(i) - hitPower);
  38.                 } else {            //When the drum get broken, re-set the initial value:
  39.  
  40.                     if (savings >= initialSet.get(i) * 3) {
  41.                         savings -= initialSet.get(i) * 3;   //Decrease savings by purchase amount..
  42.                         drumSet.set(i, initialSet.get(i));
  43.                     } else {
  44.                         drumSet.remove(i);
  45.                         initialSet.remove(i);
  46.                         i--;
  47.                     }
  48.  
  49.                 }
  50.             }
  51.  
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement