Skip to content
Open
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
1 change: 1 addition & 0 deletions ShareDatabaseApp.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="JavaFX21" level="project" />
</component>
</module>
11 changes: 11 additions & 0 deletions src/com/atden04/java/share_database_app/enums/StockStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.atden04.java.share_database_app.enums;

/**
* Enumeration for the status of the Stock
*/
public enum StockStatus {
DEFAULT,
BOUGHT,
SOLD,
LIQUIDATED
}
61 changes: 61 additions & 0 deletions src/com/atden04/java/share_database_app/models/Dividend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.atden04.java.share_database_app.models;

import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;

/**
* Class to store all data regarding the dividends of a stock.
*/
public class Dividend {
/**
* Date of the dividend being paid
*/
private SimpleStringProperty date;

/**
* Quantity of shares held on the Ex-dividend date.
*/
private SimpleFloatProperty quantity;

/**
* The amount paid to shareholders per share of the dividend
*/
private SimpleFloatProperty paymentRate;

/**
* The value of the dividend as a whole.
*/
private SimpleFloatProperty value;

/**
* Base constructor for the Dividend class
*/
public Dividend(){
this.date = new SimpleStringProperty();
this.quantity = new SimpleFloatProperty();
this.value = new SimpleFloatProperty();
this.paymentRate = new SimpleFloatProperty();
}

/**
* Overloaded constructor for the Dividend class
* @param date Date Dividend occurred
* @param quantity Quantity of shares held
* @param value Value of Dividend payment
*/
public Dividend(String date, float quantity, float value){
this.date = new SimpleStringProperty(date);
this.quantity = new SimpleFloatProperty(quantity);
this.value = new SimpleFloatProperty(value);
this.paymentRate = new SimpleFloatProperty(this.value.get()/this.quantity.get());
}

/**
* Overridden method to output the object as a string
* @return string output
*/
@Override
public String toString(){
return "Date : " + this.date + ", Quantity : " + this.quantity + ", Payment Rate : £" + this.paymentRate + ", Value : £" + this.value;
}
}
54 changes: 54 additions & 0 deletions src/com/atden04/java/share_database_app/models/Liquidation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.atden04.java.share_database_app.models;

import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;

/**
* Class to store all data regarding the liquidations of a stock.
*/
public class Liquidation {
/**
* Date of the liquidation payment being paid
*/
private SimpleStringProperty date;

/**
* Quantity of shares held at the point of liquidation
*/
private SimpleFloatProperty quantity;

/**
* The value of the liquidation payment
*/
private SimpleFloatProperty value;

/**
* Base constructor for the Liquidation class
*/
public Liquidation() {
this.date = new SimpleStringProperty();
this.quantity = new SimpleFloatProperty();
this.value = new SimpleFloatProperty();
}

/**
* Overloaded constructor for the Liquidation class
* @param date Date Liquidation payment received
* @param quantity Quantity of shares held
* @param value Value of Liquidation payment
*/
public Liquidation(String date, float quantity, float value){
this.date = new SimpleStringProperty(date);
this.quantity = new SimpleFloatProperty(quantity);
this.value = new SimpleFloatProperty(value);
}

/**
* Overridden method to output the object as a string
* @return string output
*/
@Override
public String toString(){
return "Date : "+this.date+", Quantity : "+this.quantity+", Payment : £"+this.value;
}
}
61 changes: 61 additions & 0 deletions src/com/atden04/java/share_database_app/models/Purchase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.atden04.java.share_database_app.models;

import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;

/**
* Class to store all data regarding the purchases of a stock
*/
public class Purchase {
/**
* Date of the purchase of stock
*/
private SimpleStringProperty date;

/**
* Quantity of stock bought
*/
private SimpleFloatProperty quantity;

/**
* Cost of the stock bought
*/
private SimpleFloatProperty cost;

/**
* Average (mean) cost of each share
*/
private SimpleFloatProperty costPerShare;

/**
* Base constructor for the Purchase class
*/
public Purchase() {
this.date = new SimpleStringProperty();
this.quantity = new SimpleFloatProperty();
this.cost = new SimpleFloatProperty();
this.costPerShare = new SimpleFloatProperty();
}

/**
* Overloaded constructor for the Purchase class
* @param date Date of Purchase
* @param quantity Quantity of shares purchased
* @param cost Cost of shares purchased
*/
public Purchase(String date, float quantity, float cost){
this.date = new SimpleStringProperty(date);
this.quantity = new SimpleFloatProperty(quantity);
this.cost = new SimpleFloatProperty(cost);
this.costPerShare = new SimpleFloatProperty(this.cost.get()/this.quantity.get());
}

/**
* Overridden method to output the object as a string
* @return string output
*/
@Override
public String toString(){
return "Date : "+this.date+", Quantity : "+this.quantity+", Cost : £"+this.cost+", Cost per Share : £"+this.costPerShare;
}
}
62 changes: 62 additions & 0 deletions src/com/atden04/java/share_database_app/models/Sale.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.atden04.java.share_database_app.models;

import javafx.beans.property.SimpleFloatProperty;
import javafx.beans.property.SimpleStringProperty;

/**
* Class to store all data regarding the sale of a stock
*/
public class Sale {
/**
* Date of the sale of stock
*/
private SimpleStringProperty date;

/**
* Quantity of stock sold
*/
private SimpleFloatProperty quantity;

/**
* Value of the sale
*/
private SimpleFloatProperty value;

/**
* Profit made from the sale
*/
private SimpleFloatProperty profit;

/**
* Base constructor for the Sale class
*/
public Sale() {
this.date = new SimpleStringProperty();
this.quantity = new SimpleFloatProperty();
this.value = new SimpleFloatProperty();
this.profit = new SimpleFloatProperty();
}

/**
* Overloaded constructor for the Sale class
* @param date Date of Sale
* @param quantity Quantity of stock sold
* @param value Value of the sale
* @param cost Cost to buy the stock sold
*/
public Sale(String date, float quantity, float value, float cost){
this.date = new SimpleStringProperty(date);
this.quantity = new SimpleFloatProperty(quantity);
this.value = new SimpleFloatProperty(value);
this.profit = new SimpleFloatProperty(this.value.get()-cost);
}

/**
* Overridden method to output the object as a string
* @return string output
*/
@Override
public String toString(){
return "Date : "+this.date+", Quantity : "+this.quantity+", Sale : £"+this.value+", Profit : £"+this.profit;
}
}
109 changes: 109 additions & 0 deletions src/com/atden04/java/share_database_app/models/Stock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.atden04.java.share_database_app.models;

import com.atden04.java.share_database_app.enums.StockStatus;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;

import static javafx.collections.FXCollections.observableArrayList;

public class Stock {
private SimpleStringProperty name;
private StockStatus status;
private ObservableList<Purchase> purchases;
private ObservableList<Dividend> dividends;
private ObservableList<Sale> sales;
private ObservableList<Liquidation> liquidations;
private float totalCost;
private float totalQuantity;
private float totalReturn;

public Stock() {
this.name = new SimpleStringProperty();
this.status = StockStatus.BOUGHT;
this.purchases = observableArrayList();
this.dividends = observableArrayList();
this.sales = observableArrayList();
this.liquidations = observableArrayList();
}

public Stock(String name, String status) {
this.name = new SimpleStringProperty(name);
if (status.equalsIgnoreCase("bought"))
this.status = StockStatus.BOUGHT;
else if (status.equalsIgnoreCase("sold"))
this.status = StockStatus.SOLD;
else if (status.equalsIgnoreCase("liquidated"))
this.status = StockStatus.LIQUIDATED;
this.purchases = observableArrayList();
this.dividends = observableArrayList();
this.sales = observableArrayList();
this.liquidations = observableArrayList();
}

public Stock(String name, String date, float quantity, float cost) {
this.name = new SimpleStringProperty(name);
this.status = StockStatus.BOUGHT;
this.purchases = observableArrayList();
this.dividends = observableArrayList();
this.purchases.add(new Purchase(date, quantity, cost));
this.sales = observableArrayList();
this.liquidations = observableArrayList();
this.totalCost+=cost;
this.totalQuantity+=quantity;
}

public void addPurchase(String date, float quantity, float cost) {
this.purchases.add(new Purchase(date, quantity, cost));
if (this.status != StockStatus.BOUGHT)
{
this.status = StockStatus.BOUGHT;
}
this.totalCost+=cost;
this.totalQuantity+=quantity;
}

public void addDividend(String date, float quantity, float value) {
this.dividends.add(new Dividend(date, quantity, value));
this.totalReturn+=value;
}

public void addSale(String date, float value) {
this.sales.add(new Sale(date, this.totalQuantity, value, this.totalCost));
this.status = StockStatus.SOLD;
this.totalReturn = value-this.totalCost;
this.totalQuantity = 0;
this.totalCost = 0;
}

public void addLiquidation(String date, float value) {
this.liquidations.add(new Liquidation(date, this.totalQuantity, value));
this.status = StockStatus.LIQUIDATED;
this.totalReturn+=value;
this.totalQuantity = 0;
}

public String toString() {
return "\nStock Name : "+this.getName()+", Status : "+this.getStatus()+", Quantity : "+this.totalQuantity + ", Cost : "+this.totalCost+", Return : "+this.totalReturn;
}

public String getName() {
return this.name.get();
}

public void setName(String newName) {
this.name.set(newName);
}

public StockStatus getStatus() {
return this.status;
}

public void setStatus(StockStatus newStatus) {
this.status = newStatus;
}

public ObservableList<Purchase> getPurchases(){return this.purchases;}

public ObservableList<Dividend> getDividends(){return this.dividends;}

}
Loading