Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- List<String> things = new ArrayList<>();
- double sum = 0;
- while (!input.equals("Purchase")) {
- Pattern pattern = Pattern.compile(">{2}([A-Za-z]+)<{2}([0-9]+.[0-9]+)!([0-9])");
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- String item = matcher.group(1);
- double price = Double.parseDouble(matcher.group(2));
- int quantity = Integer.parseInt(matcher.group(3));
- sum += price * quantity;
- things.add(item);
- }
- input = sc.nextLine();
- }
- System.out.println("Bought furniture:");
- for (int i = 0; i < things.size(); i++) {
- System.out.println(things.get(i));
- }
- System.out.printf("Total money spend: %.2f", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement