-
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.
- Loading branch information
martin
committed
Feb 26, 2026
1 parent
3190cb8
commit d299544
Showing
9 changed files
with
270 additions
and
0 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,48 @@ | ||
| package temppackage; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
|
|
||
| public class Exchange { | ||
| private String name; | ||
| private Map<String, Stock> stocks; | ||
| private int weekNumber; | ||
| private Random random = new Random(); | ||
|
|
||
| public Exchange(String name, List<Stock> stockList){ | ||
| this.name = name; | ||
| this.stocks = new HashMap<>(); | ||
| this.weekNumber = 1; | ||
| } | ||
|
|
||
| public void buy(Player player, Stock stock, BigDecimal quantity){ | ||
| Share shareToBuy = new Share(stock, quantity, stock.getPrice()); | ||
| Purchase purchase = new Purchase(shareToBuy, this.weekNumber); | ||
| purchase.commit(player); | ||
| } | ||
|
|
||
| public void sell(Player player, Share share){ | ||
| Sale sale = new Sale(share, weekNumber); | ||
| sale.commit(player); | ||
| } | ||
|
|
||
| public void advance(){ | ||
| this.weekNumber++; | ||
| } | ||
|
|
||
|
|
||
| public Map<String, Stock> getStocks(){ | ||
| return this.stocks; | ||
| } | ||
|
|
||
| public Stock geStock(String symbol){ | ||
| // filter med symbol eller company name | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
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,13 @@ | ||
| package temppackage; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class Player { | ||
| private String name; | ||
| private BigDecimal startingMoney; | ||
| private BigDecimal money; | ||
| private Portfolio portfolio; | ||
| private TransactionArchive transactionArchive; | ||
|
|
||
|
|
||
| } |
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,17 @@ | ||
| package temppackage; | ||
|
|
||
| public class Purchase extends Transaction{ | ||
|
|
||
|
|
||
| public Purchase(Share share, int week){ | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void commit(Player player) { | ||
| // TODO Auto-generated method stub | ||
| super.commit(player); | ||
| } | ||
|
|
||
| } |
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,36 @@ | ||
| package temppackage; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class PurchaseCalculator implements TransactionCalculator { | ||
| private BigDecimal purchasePrice; | ||
| private BigDecimal quantity; | ||
|
|
||
| public PurchaseCalculator(Share share) { | ||
| this.purchasePrice = share.getPurchasePrice(); | ||
| this.quantity = share.getQuantity(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public BigDecimal calculateGross() { | ||
| return this.purchasePrice.multiply(this.quantity); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateComission() { | ||
| BigDecimal gross = this.calculateGross(); | ||
| return gross.multiply(BigDecimal.valueOf(0.05)); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTax() { | ||
| return new BigDecimal("0"); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTotal() { | ||
| return this.calculateGross().add(this.calculateTax().add(this.calculateComission())); | ||
| } | ||
| } |
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,14 @@ | ||
| package temppackage; | ||
|
|
||
| public class Sale extends Transaction{ | ||
| public Sale(Share share, int week){ | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void commit(Player player) { | ||
| // TODO Auto-generated method stub | ||
| super.commit(player); | ||
| } | ||
|
|
||
| } |
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,43 @@ | ||
| package temppackage; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class SaleCalculator implements TransactionCalculator { | ||
| private BigDecimal purchasePrice; | ||
| private BigDecimal salesPrice; | ||
| private BigDecimal quantity; | ||
|
|
||
| public SaleCalculator(Share share) { | ||
| this.purchasePrice = share.getPurchasePrice(); | ||
| this.salesPrice = share.getStock().getPrice(); | ||
| this.quantity = share.getQuantity(); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateGross() { | ||
| return this.salesPrice.multiply(this.quantity); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateComission() { | ||
| BigDecimal gross = this.calculateGross(); | ||
| return gross.multiply(BigDecimal.valueOf(0.05)); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTax() { | ||
| BigDecimal gross = this.calculateGross(); | ||
| BigDecimal comission = this.calculateComission(); | ||
| BigDecimal buyPrice = this.purchasePrice.multiply(this.quantity); | ||
| BigDecimal earnings = gross.subtract(comission).subtract(comission).subtract(buyPrice); | ||
| return earnings.multiply(BigDecimal.valueOf(0.3)); | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal calculateTotal() { | ||
| BigDecimal gross = this.calculateGross(); | ||
| BigDecimal comission = this.calculateComission(); | ||
| BigDecimal tax = this.calculateTax(); | ||
| return gross.subtract(comission).subtract(tax); | ||
| } | ||
| } |
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,42 @@ | ||
| package temppackage; | ||
|
|
||
| import temppackage.calculators.TransactionCalculator; | ||
|
|
||
| public abstract class Transaction { | ||
| private Share share; | ||
| private int week; | ||
| private TransactionCalculator transactionCalculator; | ||
| private boolean commited; | ||
|
|
||
| protected Transaction(Share share, int week, TransactionCalculator transactionCalculator){ | ||
| this.share = share; | ||
| this.week = week; | ||
| this.transactionCalculator = transactionCalculator; | ||
| this.commited = commited; | ||
| } | ||
|
|
||
| public Share getShare(){ | ||
| return this.share; | ||
| } | ||
|
|
||
| public int getWeeek(){ | ||
| return this.week; | ||
| } | ||
|
|
||
| public TransactionCalculator getCalculator(){ | ||
| return this.transactionCalculator; | ||
| } | ||
|
|
||
| public boolean isCommitted(){ | ||
| return this.commited; | ||
| } | ||
|
|
||
| public void commit(Player player){ | ||
| //TODO | ||
| this.commited = true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
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,47 @@ | ||
| package temppackage; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class TransactionArchive { | ||
| List<Transaction> transactions; | ||
|
|
||
|
|
||
| public TransactionArchive() { | ||
| this.transactions = new ArrayList<>(); | ||
| } | ||
|
|
||
| public boolean add(Transaction transaction){ | ||
| if (transactions.contains(transaction)){ | ||
| return false; | ||
| } | ||
| this.transactions.add(transaction); | ||
| return true; | ||
| } | ||
|
|
||
| public boolean isEmpty(){ | ||
| return transactions.isEmpty(); | ||
| } | ||
|
|
||
| public List<Transaction> getTransactions(int week){ | ||
| //TODO | ||
| return null; | ||
| } | ||
|
|
||
| public List<Purchase> getPurchases(int week){ | ||
| //TODO | ||
| return null; | ||
| } | ||
|
|
||
| public List<Sale> getSales(int week){ | ||
| //TODO | ||
| return null; | ||
| } | ||
|
|
||
| public int countDistinctWeeks(){ | ||
| //TODO | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| } |
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,10 @@ | ||
| package temppackage; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public interface TransactionCalculator { | ||
| public BigDecimal calculateGross(); | ||
| public BigDecimal calculateComission(); | ||
| public BigDecimal calculateTax(); | ||
| public BigDecimal calculateTotal(); | ||
| } |