diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 148a46e..0f0af96 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -15,15 +15,20 @@ public class Main { } Scanner scanner = new Scanner(input); - // TODO: - // - Read each line from products.csv - // - For each line, parse productId, name, and price - // - The format of the file is like this: - // [productId],[name],[price] - // - Store Product objects in the productCatalog ArrayList + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); - // NOTE - // - The data in products.csv is guaranteed to be valid. + String[] parts = line.split(","); + + int productId = Integer.parseInt(parts[0].trim()); + String productName = parts[1].trim(); + double productPrice = Double.parseDouble(parts[2].trim()); + + Product product = new Product(productId, productName, productPrice); + productCatalog.add(product); + } + + scanner.close(); } public static void main(String[] args)