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