Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fund01July2018Part2;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class SoftuniBarIncome {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Pattern pattern = Pattern.compile("%([A-z][a-z]+)%.*<(\\w+).*>\\w*\\|(\\d+)\\|[a-z]*(\\d+.*\\d+)\\$");
- double totalIncome = 0.0;
- while (true) {
- String input = reader.readLine();
- if (input.equals("end of shift")) {
- break;
- }
- String name = "";
- String product = "";
- int count = 0;
- double price = 0.0;
- Matcher match = pattern.matcher(input);
- if (match.find()) {
- name = match.group(1);
- product = match.group(2);
- count = Integer.parseInt(match.group(3));
- price = Double.parseDouble(match.group(4));
- double sum = count * price;
- System.out.printf("%s: %s - %.2f%n", name, product, sum);
- totalIncome += sum;
- }
- input = input.replaceAll(String.valueOf(pattern), "");
- Pattern getCount = Pattern.compile("");
- String debug = "";
- }
- System.out.printf("Total income: %.2f", totalIncome);
- }
- }
Add Comment
Please, Sign In to add comment