From 5029fa40771606977dbf98acd9c3c6d0180daa00 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 18 Mar 2026 09:49:20 +0100 Subject: [PATCH] Fix: Changed indents to satisfy checkstyle. Also added symbol validation (4 characters) --- .../idatt2003/g40/mappe/FileConverter.java | 2 +- .../ntnu/idi/idatt2003/g40/mappe/Stock.java | 102 ++++++++++-------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/FileConverter.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/FileConverter.java index c2ef1f5..4723b7e 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/FileConverter.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/FileConverter.java @@ -54,7 +54,7 @@ public List getStocksFromStrings(final List validStocks) { stocksFromFile.add(stockObject); } } catch (IllegalArgumentException e) { - System.err.println(s + " is not a valid stock! Skipping..."); + System.err.println("(" + s + ") is not a valid stock! Skipping..."); } }); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Stock.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Stock.java index c870265..eef574a 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Stock.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Stock.java @@ -1,5 +1,6 @@ package edu.ntnu.idi.idatt2003.g40.mappe; +import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -8,57 +9,64 @@ * Represents a stock listed on an exchange. */ public class Stock { - - private final String symbol; - private final String company; - private final List prices = new ArrayList<>(); - /** - * Creates a new {@code Stock} with an initial sales price. - * - * @param symbol the unique stock symbol - * @param company the name of the company - * @param salesPrice the initial sales price of the stock - */ - public Stock(String symbol, String company, BigDecimal salesPrice){ - this.symbol = symbol; - this.company = company; - prices.add(salesPrice); - } + private final String symbol; + private final String company; + private final List prices = new ArrayList<>(); - /** - * Returns the stock symbol. - * - * @return the stock symbol - */ - public String getSymbol(){ - return symbol; - } + /** + * Creates a new {@code Stock} with an initial sales price. + * + * @param symbol the unique stock symbol + * @param company the name of the company + * @param salesPrice the initial sales price of the stock + */ + public Stock(final String symbol, + final String company, + final BigDecimal salesPrice) { - /** - * Returns the stock company. - * - * @return the stocks company - */ - public String getCompany(){ - return company; + if (symbol.length() != 4) { + throw new IllegalArgumentException( + "Stock's symbol must be 4 characters!"); } + this.symbol = symbol; + this.company = company; + prices.add(salesPrice); + } - /** - * Returns the current sales price of the stock. - * - * @return the curret sales price - */ - public BigDecimal getSalesPrice() { - return prices.getLast(); - } + /** + * Returns the stock symbol. + * + * @return the stock symbol + */ + public String getSymbol() { + return symbol; + } - /** - * Adds a new sales price to the price history. - * - * @param price the new sales price - */ - public void addNewSalesPrice(BigDecimal price) { - prices.add(price); - } + /** + * Returns the stock company. + * + * @return the stocks company + */ + public String getCompany() { + return company; + } + + /** + * Returns the current sales price of the stock. + * + * @return the current sales price + */ + public BigDecimal getSalesPrice() { + return prices.getLast(); + } + + /** + * Adds a new sales price to the price history. + * + * @param price the new sales price + */ + public void addNewSalesPrice(final BigDecimal price) { + prices.add(price); + } }