-
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.
Merge pull request #4 from danieskj/dev
Part 1 Done
- Loading branch information
Showing
31 changed files
with
1,664 additions
and
19 deletions.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Java CI with Maven | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "dev" ] | ||
| pull_request: | ||
| branches: [ "dev" ] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: self-hosted | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up JDK 25 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '25' | ||
| distribution: 'temurin' | ||
| cache: 'maven' | ||
|
|
||
| - name: Build with Maven | ||
| run: mvn -B compile --file pom.xml | ||
|
|
||
| - name: Test with Maven | ||
| run: mvn -B test --file pom.xml | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| # Mappevurdering-IDATT2003 | ||
|
|
||
| The exam of IDATT2003, "Programming 2" subject. | ||
|
|
||
| # Guide to tests | ||
|
|
||
| - The test generally start with a @BeforeEach method that sets up everything necessary for positive testing. | ||
| - Then there comes a positive test section and at last the negative tests. | ||
| - Complicated test methods have necessary JavaDocs and often have references pointing to other classes that share content or hold relevant information. | ||
| - Dictionary | ||
| - **PT** - Positive tests | ||
| - **NT** - Negative tests |
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,161 @@ | ||
| package edu.ntnu.idi.idatt; | ||
|
|
||
| import edu.ntnu.idi.idatt.marked.Share; | ||
| import edu.ntnu.idi.idatt.marked.Stock; | ||
| import edu.ntnu.idi.idatt.transaction.Purchase; | ||
| import edu.ntnu.idi.idatt.transaction.Sale; | ||
| import edu.ntnu.idi.idatt.transaction.Transaction; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.*; | ||
|
|
||
| /** | ||
| * Exchange class | ||
| * | ||
| * <p> | ||
| * Class that keeps the 'stock game' gameloop. | ||
| * Contains methods for managing game states aswell as performing | ||
| * all functionality. | ||
| * </p> | ||
| * | ||
| */ | ||
| public class Exchange { | ||
|
|
||
| private final String name; | ||
| private int week; | ||
| private HashMap<String, Stock> stockMap = new HashMap<>(); | ||
| private Random random = new Random(); | ||
|
|
||
| /** | ||
| * Constructor for Exchange class | ||
| * | ||
| * @param name - Name of the current stock Exchange | ||
| * @param stocks - List of aviable stocks for this exchange. | ||
| */ | ||
| public Exchange(String name, List<Stock> stocks) { | ||
| this.name = name; | ||
| this.week = 1; | ||
|
|
||
| for (Stock stock : stocks) { | ||
| stockMap.put(stock.getSymbol(), stock); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * | ||
| * Getters | ||
| * | ||
| * @return - their corresponding variables. | ||
| */ | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public int getWeek() { | ||
| return week; | ||
| } | ||
|
|
||
| /** | ||
| * Method for checking if a specific stock exists in the exchange. | ||
| * | ||
| * @param symbol - String symbol of a specific stock. | ||
| * @return - true/false if the exchange has the specific stock. | ||
| */ | ||
| public boolean hasStock(String symbol) { | ||
| return stockMap.containsKey(symbol); | ||
| } | ||
|
|
||
| /** | ||
| * Getter for a specific stock. | ||
| * | ||
| * @param symbol - String symbol of a specific stock. | ||
| * @return - The found stock if existant. | ||
| * @throws IllegalArgumentException if invalid symbol given. | ||
| */ | ||
| public Stock getStock(String symbol) { | ||
| if (this.hasStock(symbol)) { | ||
| return stockMap.get(symbol); | ||
| } | ||
| throw new IllegalArgumentException("This stock doesn't exist in [" + name + "] exchange."); | ||
| } | ||
|
|
||
| /** | ||
| * Method for searching after stocks. | ||
| * | ||
| * @param searchTerm - String or character sequence of corporation name / | ||
| * corresponding symbol. | ||
| * @return - List of found stocks. | ||
| */ | ||
| public List<Stock> findStocks(String searchTerm) { | ||
| ArrayList<Stock> stocksFound = new ArrayList<>(); | ||
|
|
||
| for (Stock stock : stockMap.values()) { | ||
| if (stock.getCompany().contains(searchTerm) || stock.getSymbol().contains(searchTerm)) { | ||
| stocksFound.add(stock); | ||
| } | ||
| } | ||
| return stocksFound; | ||
| } | ||
|
|
||
| /** | ||
| * Method to allow a player to buy a stock. | ||
| * | ||
| * <p> | ||
| * Executes a purchase for a player which executes all logic | ||
| * and management of money, portfolio and archive. | ||
| * </p> | ||
| * | ||
| * @see Purchase | ||
| * | ||
| * @param symbol - The symbol of the bought stock. | ||
| * @param quantity - The amount of a bought stock. | ||
| * @param player - which player did this event. | ||
| * @return The given transaction details. (Transaction). | ||
| * @see Transaction | ||
| */ | ||
| public Transaction buy(String symbol, BigDecimal quantity, Player player) { | ||
| Share share = new Share(getStock(symbol), quantity, BigDecimal.valueOf(random.nextDouble())); | ||
| Purchase purchase = new Purchase(share, this.week); | ||
| purchase.commit(player); | ||
| return player.getTransactionArchive().getPurchases(this.week).getLast(); | ||
| } | ||
|
|
||
| /** | ||
| * Method to allow a player to sell a stock. | ||
| * | ||
| * <p> | ||
| * Executes a sale for a player which executes all logic | ||
| * and management of money, portfolio and archive. | ||
| * </p> | ||
| * | ||
| * @see Sale | ||
| * | ||
| * @param Share - The instance of the sold share. | ||
| * @param player - which player did this event. | ||
| * @return The given transaction details. (Transaction). | ||
| * @see Transaction | ||
| */ | ||
| public Transaction sell(Share share, Player player) { | ||
| Sale sale = new Sale(share, this.week); | ||
| sale.commit(player); | ||
| return player.getTransactionArchive().getSales(this.week).getLast(); | ||
| } | ||
|
|
||
| /** | ||
| * Method to advance the gameloop. | ||
| * | ||
| * <p> | ||
| * Adds a new price to each of the stock array. | ||
| * </p> | ||
| * | ||
| * @see Stock | ||
| */ | ||
| public void advance() { | ||
| for (Stock stocks : stockMap.values()) { | ||
| stocks.addNewSalesPrice(BigDecimal.valueOf(random.nextDouble())); | ||
| } | ||
| } | ||
|
|
||
| } |
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 |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ static void main() { | |
| System.out.println("Hello world!"); | ||
| } | ||
|
|
||
| } | ||
| } | ||
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,57 @@ | ||
| package edu.ntnu.idi.idatt; | ||
|
|
||
| import edu.ntnu.idi.idatt.marked.Portfolio; | ||
| import edu.ntnu.idi.idatt.transaction.TransactionArchive; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class Player { | ||
|
|
||
| private final String name; | ||
| private final BigDecimal startingMoney; | ||
| private BigDecimal money; | ||
| private Portfolio portfolio = new Portfolio(); | ||
| private TransactionArchive transactionArchive = new TransactionArchive(); | ||
|
|
||
| public Player(String name, BigDecimal startingMoney) { | ||
| this.name = name; | ||
| this.startingMoney = startingMoney; | ||
| this.money = this.startingMoney; | ||
| } | ||
|
|
||
| /** | ||
| * Getters | ||
| * | ||
| * @return - Their corresponding variables. | ||
| */ | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public BigDecimal getMoney() { | ||
| return money; | ||
| } | ||
|
|
||
| public Portfolio getPortfolio() { | ||
| return portfolio; | ||
| } | ||
|
|
||
| public TransactionArchive getTransactionArchive() { | ||
| return transactionArchive; | ||
| } | ||
|
|
||
| /** | ||
| * Setters for money | ||
| * | ||
| * @param amount - Amount to be changed correspondingly. | ||
| */ | ||
|
|
||
| public void addMoney(BigDecimal amount) { | ||
| this.money = this.money.add(amount); | ||
| } | ||
|
|
||
| public void withdrawMoney(BigDecimal amount) { | ||
| this.money = this.money.subtract(amount); | ||
| } | ||
| } |
Oops, something went wrong.