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