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