-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikollai
committed
Mar 11, 2026
1 parent
35bf19c
commit 072dbc1
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package millions; | ||
|
|
||
| import java.io.*; | ||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class StockInformationCSVWriter { | ||
| private final List<Stock> stocks; | ||
| private final File destinationFile; | ||
|
|
||
| public StockInformationCSVWriter(List<Stock> stocks,File destinationFile) { | ||
| this.stocks = stocks; | ||
| this.destinationFile = destinationFile; | ||
| } | ||
|
|
||
| public void write() { | ||
| StringBuilder builder = new StringBuilder(); | ||
| for (Stock stock : stocks) { | ||
| builder.append(stock.getSymbol()); | ||
| builder.append(","); | ||
| builder.append(stock.getCompany()); | ||
| builder.append(","); | ||
| // Unsure if price history or just latest price should be saved | ||
| builder.append(stock.getSalesPrice().toPlainString()); | ||
| builder.append("\n"); | ||
| } | ||
| try (FileWriter writer = new FileWriter(destinationFile); BufferedWriter bufferedWriter = new BufferedWriter(writer)) { | ||
| bufferedWriter.write(builder.toString()); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } |