Complete class main
This commit is contained in:
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/HW-06-exceptions-and-file-handling.iml" filepath="$PROJECT_DIR$/HW-06-exceptions-and-file-handling.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+11
-8
@@ -13,17 +13,20 @@ public class Main {
|
|||||||
if (input == null) {
|
if (input == null) {
|
||||||
throw new IOException("products.csv not found");
|
throw new IOException("products.csv not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner scanner = new Scanner(input);
|
Scanner scanner = new Scanner(input);
|
||||||
|
|
||||||
// TODO:
|
while (scanner.hasNextLine())
|
||||||
// - Read each line from products.csv
|
{
|
||||||
// - For each line, parse productId, name, and price
|
String line = scanner.nextLine();
|
||||||
// - The format of the file is like this:
|
String[] parts = line.split(",");
|
||||||
// [productId],[name],[price]
|
int id = Integer.parseInt(parts[0].trim());
|
||||||
// - Store Product objects in the productCatalog ArrayList
|
String name = parts[1].trim();
|
||||||
|
Double price = Double.parseDouble(parts[2].trim());
|
||||||
|
|
||||||
// NOTE
|
productCatalog.add(new Product(id, name, price));
|
||||||
// - The data in products.csv is guaranteed to be valid.
|
}
|
||||||
|
scanner.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
|||||||
Reference in New Issue
Block a user