Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class _05_DrumSet {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double savings = Double.parseDouble(scanner.nextLine());
- //Here we put the initial values of drums's quality:
- List<Integer> initialSet = Arrays.stream(scanner.nextLine()
- .split("\\s+"))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- //Here we change the values through the usage:
- List<Integer> drumSet = new ArrayList<>();
- drumSet.addAll(initialSet);
- String input = "";
- int counter = 0;
- while (true) {
- input = scanner.nextLine();
- if (input.equals("Hit it again, Gabsy!")) {
- for (Integer integer : drumSet) {
- System.out.print(integer + " ");
- }
- System.out.println();
- System.out.printf("Gabsy has %.2flv.%n", savings);
- break;
- }
- int hitPower = Integer.parseInt(input);
- //While hitting the drums, decreasing the quality:
- for (int i = 0; i < drumSet.size(); i++) {
- if (drumSet.get(i) > hitPower) {
- drumSet.set(i, drumSet.get(i) - hitPower);
- } else { //When the drum get broken, re-set the initial value:
- if (savings >= initialSet.get(i) * 3) {
- savings -= initialSet.get(i) * 3; //Decrease savings by purchase amount..
- drumSet.set(i, initialSet.get(i));
- } else {
- drumSet.remove(i);
- initialSet.remove(i);
- i--;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement