tamrin 6
This commit is contained in:
+11
-12
@@ -14,20 +14,19 @@ public class Main {
|
||||
throw new IOException("products.csv not found");
|
||||
}
|
||||
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
|
||||
|
||||
// NOTE
|
||||
// - The data in products.csv is guaranteed to be valid.
|
||||
while (scanner.hasNextLine()){
|
||||
String line = scanner.nextLine();
|
||||
String[] lineArray = line.split(",");
|
||||
int productID = Integer.parseInt(lineArray[0]);
|
||||
String productName = lineArray[1];
|
||||
double price = Double.parseDouble(lineArray[2]);
|
||||
Product pro = new Product(productID ,productName,price);
|
||||
productCatalog.add(pro);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
try {
|
||||
loadProducts();
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user