implement Main.java

This commit is contained in:
2026-05-19 14:42:49 -07:00
parent 8e6d1d1760
commit e4d0d6febb
+13 -8
View File
@@ -15,15 +15,20 @@ public class Main {
} }
Scanner scanner = new Scanner(input); Scanner scanner = new Scanner(input);
// TODO: while (scanner.hasNextLine()) {
// - Read each line from products.csv String line = scanner.nextLine();
// - 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
// NOTE String[] parts = line.split(",");
// - The data in products.csv is guaranteed to be valid.
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) public static void main(String[] args)