Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import javafx.util.Pair;
- import javax.xml.crypto.dsig.keyinfo.KeyValue;
- import java.security.KeyStore;
- import java.text.Collator;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.function.Predicate;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collector;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String regex = ">>(?<furniture>[A-Za-z]+)<<(?<price>\\d+.?\\d+)!(?<quantity>\\d+)";
- Pattern pattern = Pattern.compile(regex);
- List<String> boughtFurniture = new ArrayList<>();
- Double total = 0.0;
- String input;
- while (!"Purchase".equals(input = scanner.nextLine())){
- Matcher purchases = pattern.matcher(input);
- if(purchases.find()) {
- String furniture = purchases.group("furniture");
- double price = Double.parseDouble(purchases.group("price"));
- int quantity = Integer.parseInt(purchases.group("quantity"));
- boughtFurniture.add(furniture);
- total += price * quantity;
- }
- }
- System.out.println("Bought furniture:");
- for (String furniture : boughtFurniture){
- System.out.println(furniture);
- }
- System.out.printf("Total money spend: %.2f", total);
- }
- }
Add Comment
Please, Sign In to add comment