Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ListsMoreExercise;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class O5DrumSet {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double money = Double.parseDouble(scanner.nextLine());
- List<Integer> a = Arrays.stream(scanner.nextLine().split("\\s+"))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- List<Integer> priceList = new ArrayList<>(a);
- String command = scanner.nextLine();
- while (!command.equals("Hit it again, Gabsy!")) {
- for (int i = 0; i < a.size(); i++) {
- int power = Integer.parseInt(command);
- a.set(i, a.get(i) - power);
- if (a.get(i) <= 0) {
- double price = priceList.get(i) * 3;
- if (money >= price) {
- a.set(i, priceList.get(i));
- money -= price;
- } else {
- a.remove(i);
- priceList.remove(i);
- i--;
- }
- }
- }
- command = scanner.nextLine();
- }
- for (int drum : a) {
- System.out.print(drum + " ");
- }
- System.out.println();
- System.out.printf("Gabsy has %.2flv.", money);
- }
- }
Add Comment
Please, Sign In to add comment