Skip to content

implement logic in the TransactionArchive class #30

Merged
merged 2 commits into from
Feb 23, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 11 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Portfolio.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public Portfolio() {
* @return true or false based on if the operation was successful or not.
*/
public boolean addShare(Share share) {
return true;
if (share == null) {
return false;
} else {
return shares.add(share);
}
}

/**
Expand All @@ -32,7 +36,11 @@ public boolean addShare(Share share) {
* @return true or false based on if the operation was successful or not.
*/
public boolean removeShare(Share share) {
return false;
if (share == null || !shares.contains(share)) {
return false;
} else {
return shares.remove(share);
}
}

public List<Share> getShares() {
Expand All @@ -45,6 +53,6 @@ public List<Share> getShares() {
* @return true or false based on if the share was found or not.
*/
public boolean contains(Share share) {
return true;
return share != null && shares.contains(share);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.ntnu.idi.idatt2003.gruppe42.Model.Transaction;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class TransactionArchive {
private List<Transaction> transactions;
Expand All @@ -11,26 +13,60 @@ public TransactionArchive() {
}

public boolean add(Transaction transaction) {
return true;
if (transaction == null) {
return false;
} else {
return transactions.add(transaction);
}
}

public boolean isEmpty() {
return true;
return transactions.isEmpty();
}

public List<Transaction> getTransactions(int week) {
return transactions;
List<Transaction> transactionsThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week) {
transactionsThisWeek.add(transaction);
}
}

return transactionsThisWeek;
}

public List<Purchase> getPurchases(int week) {
return null;
List<Purchase> purchasesThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week && transaction instanceof Purchase) {
purchasesThisWeek.add((Purchase) transaction);
}
}

return purchasesThisWeek;
}

public List<Sale> getSales(int week) {
return null;
List<Sale> salesThisWeek = new ArrayList<>();

for (Transaction transaction : transactions) {
if (transaction.getWeek() == week && transaction instanceof Sale) {
salesThisWeek.add((Sale) transaction);
}
}

return salesThisWeek;
}

public int countDistinctWeeks() {
return 0;
Set<Integer> distinctWeeks = new HashSet<>();

for (Transaction transaction : transactions) {
distinctWeeks.add(transaction.getWeek());
}

return distinctWeeks.size();
}
}