Advertisement
Ligh7_of_H3av3n

04. Add VAT

May 27th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package Lekciq;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.function.UnaryOperator;
  7. import java.util.stream.Collectors;
  8.  
  9. public class AddVAT {
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.  
  14.         // Read input line
  15.         String input = scanner.nextLine();
  16.  
  17.         // Define a unary operator to add VAT
  18.         UnaryOperator<Double> addVAT = price -> price * 1.20;
  19.  
  20.         // Split the input into strings, parse them to doubles, add VAT, and collect into a list
  21.         List<Double> pricesWithVAT = Arrays.stream(input.split(", "))
  22.                 .map(Double::parseDouble)
  23.                 .map(addVAT)
  24.                 .collect(Collectors.toList());
  25.  
  26.         // Print the prices with VAT
  27.         System.out.println("Prices with VAT:");
  28.         pricesWithVAT.forEach(price -> System.out.printf("%.2f%n", price));
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement