Skip to content

Commit

Permalink
Merge pull request #65 from danieskj/documentation
Browse files Browse the repository at this point in the history
Documentation
  • Loading branch information
pawelsa authored May 25, 2026
2 parents d493cca + bfb8f9b commit 1186b1e
Show file tree
Hide file tree
Showing 82 changed files with 3,484 additions and 379 deletions.
6 changes: 6 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ static void main() {
Application.launch(Millions.class);
}

/**
* Class for JavaFX startup.
*/
public static final class Millions extends Application {

/**
* JavaFX entry point.
*/
@Override
public void start(Stage stage) {
stage.setWidth(1440);
Expand Down
33 changes: 21 additions & 12 deletions src/main/java/edu/ntnu/idi/idatt/model/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,28 @@ public Exchange(String name, List<Stock> stocks) {
}

/**
*
* Getters
*
* @return - their corresponding variables.
* Getter for name.
*
* @return String;
*/

public String getName() {
return name;
}

/**
* Getter for week.
*
* @return int;
*/
public int getWeek() {
return week;
}

/**
* Getter for all stocks.
*
* @return List of Stocks.
*/
public List<Stock> getStocks() {
return stockMap.values().stream().toList();
}
Expand Down Expand Up @@ -106,16 +114,16 @@ public List<Stock> findStocks(String searchTerm) {
*
* <p>
* Returns the stocks that have done it the best
* in the latest week.
* (percent change) in the latest week.
* </p>
*
* @param limit - Amount of stocks to be returned.
* @return A list of stocks sorted in declining order.
*/
public List<Stock> getGainers(int limit) {
return stockMap.values().stream()
.filter(stock -> stock.getLatestPriceChange().compareTo(BigDecimal.ZERO) > 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChange).reversed())
.filter(stock -> stock.getLatestPriceChangePercent().compareTo(BigDecimal.ZERO) > 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChangePercent).reversed())
.limit(limit)
.toList();
}
Expand All @@ -125,16 +133,16 @@ public List<Stock> getGainers(int limit) {
*
* <p>
* Returns the stocks that have done it the worst
* in value in the latest week.
* in percent change in the latest week.
* </p>
*
* @param limit - Amount of stocks to be returned.
* @return A list of stocks sorted in inclining order.
* @return A list of stocks sorted in ascending order.
*/
public List<Stock> getLosers(int limit) {
return stockMap.values().stream()
.filter(stock -> stock.getLatestPriceChange().compareTo(BigDecimal.ZERO) < 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChange))
.filter(stock -> stock.getLatestPriceChangePercent().compareTo(BigDecimal.ZERO) < 0)
.sorted(Comparator.comparing(Stock::getLatestPriceChangePercent))
.limit(limit)
.toList();
}
Expand Down Expand Up @@ -189,6 +197,7 @@ public Transaction sell(Share share, Player player) {
*
* <p>
* Adds a new price to each of the stock array.
* Progresses week counter.
* </p>
*
* @see Stock
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package edu.ntnu.idi.idatt.model.enums;

/**
* Newspaper enum.
*
* <p>
* Creates static events that can occur within Newspaper.
* </p>
*
* @see Newspaper
*/
public enum NewspaperEnum {
NEW_PRODUCT(
"New product announced!",
Expand Down Expand Up @@ -83,25 +92,48 @@ public enum NewspaperEnum {
private final double trend;
private final double volatility; // How violently the price moves factor

/**
* Constructor for NewspaperEnum
*/
NewspaperEnum(String title, String description, double trend, double volatility) {
this.title = title;
this.description = description;
this.trend = trend;
this.volatility = volatility;
}

/**
* Getter for title
*
* @return String;
*/
public String getTitle() {
return title;
}

/**
* Getter for description
*
* @return String;
*/
public String getDescription() {
return description;
}

/**
* Getter for trend
*
* @return double;
*/
public double getTrend() {
return trend;
}

/**
* Getter for volatility
*
* @return double;
*/
public double getVolatility() {
return volatility;
}
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/model/enums/PlayerStatusEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package edu.ntnu.idi.idatt.model.enums;

import java.math.BigDecimal;

import edu.ntnu.idi.idatt.model.player.Player;

/**
* Enum class that holds the different player statuses.
*
* @see Player
*/
public enum PlayerStatusEnum {
ROARING_KITTY("Roaring Kitty", 50, new BigDecimal("8")),
PAPER_HANDS("Paper Hands", 100, new BigDecimal("2")),
SPECULATOR("Speculator", 20, new BigDecimal("2")),
DIAMOND_HANDS("Diamond Hands", 10, new BigDecimal("3")),
INVESTOR("Investor", 10, new BigDecimal("1.2")),
NOVICE("Novice", 0, BigDecimal.ZERO);

private final String title;
private final int tradingWeeks;
private final BigDecimal ratio;

/**
* Constructor for PlayerStatusEnum
*
* @param title - Status name
* @param tradingWeeks - How many weeks in trading to reach status.
* @param ratio - NetWorth/starting money
*/
PlayerStatusEnum(String title, int tradingWeeks, BigDecimal ratio) {
this.title = title;
this.tradingWeeks = tradingWeeks;
this.ratio = ratio;
}

/**
* Getter for title.
*
* @return String;
*/
public String getTitle() {
return title;
}

/**
* Getter for trading weeks.
*
* @return int;
*/
public int getTradingWeeks() {
return tradingWeeks;
}

/**
* Getter for ratio.
*
* @return BigDecimal.
*/
public BigDecimal getRatio() {
return ratio;
}

}
38 changes: 38 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/model/market/Newspaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@

import edu.ntnu.idi.idatt.model.enums.NewspaperEnum;

/**
* Newspaper class
*
* <p>
* This class is used together with Stock,
* to provide a event-based context for the
* prices.
* </p>
*
* @see Stock
*/
public class Newspaper {

ArrayList<NewspaperEnum> news = new ArrayList<>(List.of(NewspaperEnum.NONE_EVENT));
private static double chance = 0.05; // In percent

/**
* Method for creating news.
*
* <p>
* Creates news and adds them to the
* news ArrayList.
* </p>
*
* @return NewspaperEnum of NONE or random event.
*/
public NewspaperEnum makeNews() {
Random r = new Random();
double roll = r.nextDouble();
Expand All @@ -27,14 +48,31 @@ public NewspaperEnum makeNews() {
return event;
}

/**
* Method for checking if Newspaper has new news.
*
* @return true/false depending if a real event exists.
*/
public boolean hasNewNews() {
return news.getLast().equals(NewspaperEnum.NONE_EVENT) ? false : true;
}

/**
* Getter for news arraylist.
*/
public ArrayList<NewspaperEnum> getNews() {
return news;
}

/**
* Method for converting the arraylist to formatted strings.
*
* <p>
* Converts NewspaperEnum to fitting String format.
* </p>
*
* @return List of strings.
*/
public List<String> getNewsStrings() {

ArrayList<String> strings = new ArrayList<>();
Expand Down
Loading

0 comments on commit 1186b1e

Please sign in to comment.