Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekciq;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.function.UnaryOperator;
- import java.util.stream.Collectors;
- public class AddVAT {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // Read input line
- String input = scanner.nextLine();
- // Define a unary operator to add VAT
- UnaryOperator<Double> addVAT = price -> price * 1.20;
- // Split the input into strings, parse them to doubles, add VAT, and collect into a list
- List<Double> pricesWithVAT = Arrays.stream(input.split(", "))
- .map(Double::parseDouble)
- .map(addVAT)
- .collect(Collectors.toList());
- // Print the prices with VAT
- System.out.println("Prices with VAT:");
- pricesWithVAT.forEach(price -> System.out.printf("%.2f%n", price));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement