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) {
|
||||
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
|
||||
while (scanner.hasNextLine())
|
||||
{
|
||||
String line = scanner.nextLine();
|
||||
String[] parts = line.split(",");
|
||||
int id = Integer.parseInt(parts[0].trim());
|
||||
String name = parts[1].trim();
|
||||
Double price = Double.parseDouble(parts[2].trim());
|
||||
|
||||
// NOTE
|
||||
// - The data in products.csv is guaranteed to be valid.
|
||||
productCatalog.add(new Product(id, name, price));
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
|
||||
Reference in New Issue
Block a user