Skip to content

Part 1 Done #4

Merged
merged 54 commits into from
Mar 10, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b8bdead
feat: Add Stock class. Simple constructor with getters/setters. Basic…
pawelsa Feb 12, 2026
21d7a83
feat: Add Share class. Simple constructor with getters/setters. Basic…
pawelsa Feb 12, 2026
f8cbbd6
feat: Add Portfolio class. Implemented simple methods for share manag…
pawelsa Feb 12, 2026
dbd2425
chore(Share.class): Modify JavaDoc description mistake.
pawelsa Feb 12, 2026
5f9a3e8
feat: Create TransactionCalculator interface
pawelsa Feb 12, 2026
b0621ae
feat: Implemented PurchaseCalculator and SaleCalculator with project …
pawelsa Feb 12, 2026
4eda27a
chore: Rename package (transaction -> calculator)
pawelsa Feb 12, 2026
eea854c
feat: Create Transaction abstract class
pawelsa Feb 12, 2026
0b29c14
feat: Implement Purchase and Sale classes
pawelsa Feb 12, 2026
9a3d706
Fix: Missing class accessibility scope
pawelsa Feb 12, 2026
b289cbc
feat: Temporary player class
pawelsa Feb 12, 2026
9793281
feat: Add TransactionArchive class to store per player transaction lo…
pawelsa Feb 12, 2026
8250eee
feat: Implementation of Player class structure
pawelsa Feb 12, 2026
ce4985b
fix(Player class): Variable values on instance creation.
pawelsa Feb 12, 2026
777184d
feat: Added commit method bodies to Purchase and Sale
pawelsa Feb 12, 2026
326ed30
fix: Accessibility modifiers
pawelsa Feb 12, 2026
cf8ebfe
feat: Added Exchange class as backbone of the project.
pawelsa Feb 12, 2026
22ee5e8
Merge pull request #1 from danieskj/pawel-sapula/basic-structure
danieskj Feb 12, 2026
d802061
chore: Google java style cleanup (checkstyle)
pawelsa Feb 13, 2026
a4e968c
chore: Set unspecified variable
pawelsa Feb 13, 2026
b30e599
chore: JavaDocs, Set unspecified return.
pawelsa Feb 13, 2026
766a141
chore(Purchase, Sale): Add JavaDoc and reorganize imports.
pawelsa Feb 13, 2026
f25f4fb
feat: add JUnit tests structure
pawelsa Feb 13, 2026
df77f35
fix: pom.xml dependency/plugins reorganization
pawelsa Feb 13, 2026
6ca4068
feat(Stock): Add initial tests and fix corresponding class.
pawelsa Feb 13, 2026
b5f06fb
feat(Share): Add initial tests.
pawelsa Feb 13, 2026
cbda1fb
feat(Portfolio): Add initial tests and fix corresponding class.
pawelsa Feb 14, 2026
5ab252d
feat(PurchaseCalculator): Add initial tests.
pawelsa Feb 15, 2026
e85d4ae
feat(SaleCalculator): Add initial tests and fix corresponding class.
pawelsa Feb 15, 2026
a497a75
feat(Purchase): Add initial tests.
pawelsa Feb 15, 2026
1c4ce00
feat(Sale): Add initial tests.
pawelsa Feb 15, 2026
a1facac
chore: Removed redundant test classes.
pawelsa Feb 15, 2026
553bc00
feat(TransactionArchive): Add initial tests and fix corresponding class.
pawelsa Feb 15, 2026
778cb4d
feat(Player): Add initial tests.
pawelsa Feb 15, 2026
1cef437
feat(Exchange): Add initial tests and fix corresponding class.
pawelsa Feb 16, 2026
3a6400d
chore(Test classes): cleanup code and some JavaDocs.
pawelsa Feb 16, 2026
1ed22c0
feat(Portfolio): Add exception.
pawelsa Feb 16, 2026
b2fb41e
refactor: README.md about tests.
pawelsa Feb 16, 2026
a0fb680
feat(gui): Added some more dependencies for javafx in the pom file
Feb 17, 2026
3b64b8e
feat(gui): Added picture and a starting scene
Feb 17, 2026
56b78f7
feat(gui): Added buttons to first and second scene
Feb 17, 2026
27f5b4a
chore: Cleanup.i
Feb 18, 2026
1cfcd0a
Merge pull request #2 from danieskj/pawel-sapula/testing-exceptions
danieskj Feb 18, 2026
d0deecf
Merge branch 'dev' into danieskj/testing_javafx
danieskj Feb 18, 2026
d00d7ad
Merge pull request #3 from danieskj/danieskj/testing_javafx
pawelsa Feb 18, 2026
a79cd61
fix: pom.xml after merge conflict
pawelsa Feb 18, 2026
0723ae2
Create maven.yml
danieskj Feb 18, 2026
62941a2
Update maven.yml
danieskj Feb 18, 2026
42215b5
Update maven.yml
danieskj Feb 18, 2026
653ab9e
Update maven.yml
danieskj Feb 18, 2026
b4db772
Update maven.yml
danieskj Feb 18, 2026
8c3e1f5
Update maven.yml
danieskj Feb 18, 2026
c9029c9
Update maven.yml
danieskj Feb 18, 2026
18d72fd
Update maven.yml
danieskj Feb 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/maven.yml
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

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions README.md
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
59 changes: 42 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</dependency>


<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -39,19 +33,56 @@
<version>25.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>25.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>25.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>25.0.1</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>25.0.1</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.0.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<plugins>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>


<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>edu.ntnu.idi.idatt.Main</mainClass>
<mainClass>edu.ntnu.idi.idatt.gui.javafx</mainClass>
</configuration>
</plugin>

Expand All @@ -78,13 +109,7 @@
</configuration>
</plugin>

<plugin>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>6.0.1</version>
</plugin>

</plugins>
</plugins>
</build>

</project>
</project>
161 changes: 161 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/Exchange.java
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()));
}
}

}
2 changes: 1 addition & 1 deletion src/main/java/edu/ntnu/idi/idatt/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ static void main() {
System.out.println("Hello world!");
}

}
}
57 changes: 57 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/Player.java
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);
}
}
Loading