Skip to content

Commit

Permalink
Fix: Changed indents to satisfy checkstyle. Also added symbol validat…
Browse files Browse the repository at this point in the history
…ion (4 characters)
  • Loading branch information
tommyah committed Mar 18, 2026
1 parent 6f83a46 commit 5029fa4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Stock> getStocksFromStrings(final List<String> 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...");
}

});
Expand Down
102 changes: 55 additions & 47 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Stock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BigDecimal> 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<BigDecimal> 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);
}
}

0 comments on commit 5029fa4

Please sign in to comment.