diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java index 467734a..9fb9000 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Exchange.java @@ -4,7 +4,6 @@ import edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction.Purchase; import edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction.Sale; import edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction.Transaction; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; @@ -12,6 +11,13 @@ import java.util.Map; import java.util.Random; +/** + * Represents a stock exchange where players can buy and sell shares. + *
+ * The {@code Exchange} keeps track of available stocks, the current week in the simulation, + * and allows players to perform transactions such as buying or selling shares. + *
+ */ public class Exchange { private String name; private int week; @@ -19,6 +25,12 @@ public class Exchange { private Random random; private List+ * The player’s money is withdrawn by the quantity amount, and a {@code Purchase} transaction is returned. + *
+ * + * @param symbol the symbol of the stock to buy + * @param quantity the amount of stock to buy + * @param player the player performing the purchase + * @return a {@code Purchase} transaction representing the purchase + */ public Transaction buy(String symbol, BigDecimal quantity, Player player) { player.withdrawMoney(quantity); @@ -64,12 +105,25 @@ public Transaction buy(String symbol, BigDecimal quantity, Player player) { return new Purchase(share, week); } + /** + * Allows a player to sell a share on the exchange. + *+ * The player receives money based on the sale calculation, and a {@code Sale} transaction is returned. + *
+ * + * @param share the share to sell + * @param player the player performing the sale + * @return a {@code Sale} transaction representing the sale + */ public Transaction sell(Share share, Player player) { SaleCalculator saleCalculator = new SaleCalculator(share); player.addMoney(saleCalculator.calculateTotal()); return new Sale(share, week); } + /** + * Advances the simulation by 1 week. + */ public void advance() { week += 1; } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java index b5dff97..d505c60 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Player.java @@ -4,8 +4,12 @@ import java.math.BigDecimal; /** - * Player represents the user, the money they own, and their portfolio. - * The class includes methods for adding and withdrawing money from the players portfolio. + * Represents a player in the stock market simulation. + *+ * A {@code Player} has a name, starting money, current money balance, + * a {@link Portfolio} of shares, and a {@link TransactionArchive} of past transactions. + * The player can add or withdraw money, and manage their portfolio through purchases and sales. + *
*/ public class Player { private final String name; @@ -15,9 +19,10 @@ public class Player { private TransactionArchive transactionArchive; /** + * Constructs a new {@code Player} with a name and starting money. * - * @param name - * @param startingMoney + * @param name the name of the player + * @param startingMoney the initial amount of money the player has */ public Player(String name, BigDecimal startingMoney) { this.name = name; @@ -45,16 +50,18 @@ public BigDecimal getMoney() { } /** + * Adds the specified amount of money to the player's balance. * - * @param amount is the amount that will be added to players account. + * @param amount the amount to add to the player's account */ public void addMoney(BigDecimal amount) { money = money.add(amount); } /** + * Withdraws the specified amount of money from the player's balance. * - * @param amount is the amount that will be withdrawn from players account. + * @param amount the amount to withdraw from the player's account */ public void withdrawMoney(BigDecimal amount) { money = money.subtract(amount); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java index 0c39fb4..e1ef3ec 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java @@ -4,23 +4,27 @@ import java.util.List; /** - * Portfolio represents a collection of {@link Share} objects owned by a {@link Player}. - * The class includes methods for adding, removing and getting shares from the portfolio. + * Represents a collection of {@link Share} objects owned by a {@link Player}. + *+ * A {@code Portfolio} allows adding, removing, and querying shares. + * It serves as the player's collection of owned shares. + *
*/ public class Portfolio { private List+ * A {@code Share} keeps track of the stock it represents, the quantity owned, + * and the purchase price at which it was bought. + *
+ */ public class Share { private Stock stock; private BigDecimal quantity; private BigDecimal purchasePrice; + /** + * Constructs a new {@code Share} given the given stock, quantity, and purchase price. + * @param stock stock the stock that this share represents + * @param quantity quantity the number of shares owned + * @param purchasePrice purchasePrice the price per share at the time of purchase + */ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { this.stock = stock; this.quantity = quantity; diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java index bd4192c..6472647 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Stock.java @@ -4,11 +4,24 @@ import java.util.ArrayList; import java.util.List; +/** + * Represents a stock of a company in the {@link Exchange}. + *+ * Each {@code Stock} has a unique symbol, a company name, and a history of sales prices. + * You can retrieve the current price or add new prices as the market changes. + *
+ */ public class Stock { private final String symbol; private final String company; private List