implement Main.java
This commit is contained in:
+13
-8
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user