Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.util.ArrayList;
- import java.util.Locale;
- import java.util.Scanner;
- public class _10_OrderOfProducts {
- public static void main(String[] args) throws Exception {
- Locale.setDefault(Locale.ROOT);
- ArrayList<Product> products = new ArrayList<Product>();
- try (Scanner input = new Scanner(new FileReader("Products.txt"))) {
- while (input.hasNextLine()) {
- products.add(new Product(input.next(), input.nextDouble()));
- }
- }
- double result = 0;
- try (Scanner input = new Scanner(new FileReader("Order.txt"))) {
- while (input.hasNextLine()) {
- double quantity = input.nextDouble();
- String currentProduct = input.next();
- for (Product product : products) {
- if (product.getName().equals(currentProduct)) {
- result += quantity * product.getPrice();
- }
- }
- }
- }
- try (BufferedWriter output = new BufferedWriter(new FileWriter("Output.txt"))) {
- output.write(String.format("%.2f", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement