I fixed the main part and part of the report.
This commit is contained in:
+48
-2
@@ -14,6 +14,53 @@ public class Main {
|
||||
throw new IOException("products.csv not found");
|
||||
}
|
||||
Scanner scanner = new Scanner(input);
|
||||
while (scanner.hasNextLine())
|
||||
{
|
||||
String ln = scanner.nextLine() ;
|
||||
int part_number = 0 ;
|
||||
String part = "";
|
||||
String product_id = "" ;
|
||||
String product_name = "" ;
|
||||
String product_price = "" ;
|
||||
for (char x : ln.toCharArray() )
|
||||
{
|
||||
|
||||
if (x != ',')
|
||||
{
|
||||
part = part + x ;
|
||||
}
|
||||
else if (x == ',')
|
||||
{
|
||||
switch (part_number)
|
||||
{
|
||||
case 0 :
|
||||
product_id = part ;
|
||||
part = "" ;
|
||||
part_number ++ ;
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
product_name = part ;
|
||||
part = "" ;
|
||||
part_number ++ ;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
product_price = part ;
|
||||
part = "" ;
|
||||
part_number ++ ;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
productCatalog.add(new Product(Integer.parseInt(product_id), product_name , Float.parseFloat(product_price))) ;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// - Read each line from products.csv
|
||||
@@ -26,8 +73,7 @@ public class Main {
|
||||
// - The data in products.csv is guaranteed to be valid.
|
||||
}
|
||||
|
||||
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