////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : transaction //This class defines the transaction structure. It defines methods to extract //the attributes of a transaction. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.util.*; import java.text.DateFormat; public class Transaction{ public boolean Bank; public String Details; public int Day; public int Month; public int Year; public int NumShares; public double CostOfShare; public double AmountTransacted; public boolean TransType;//For bank: 0=>credit, 1=> debit : For shares 0=> buy 1=> sell public Transaction(){ } public Transaction(String details, int day,int month,int year, int numShares, double costOfShare,boolean transType){ Bank = false; this.Details = details; this.Day=day; this.Month=month; this.Year=year; this.NumShares = numShares; this.CostOfShare = costOfShare; this.TransType=transType; } public Transaction(String details, int day,int month,int year, double amountTransacted,boolean transType){ Bank = true; this.Details = details; this.Day=day; this.Month=month; this.Year=year; this.AmountTransacted = amountTransacted; this.TransType=transType; } //Returns the number of fields for records public int FieldLength(){ if(Bank) return(4); else return(5); } //returns the string of date public String Date(){ return(Day+"/"+Month+"/"+Year); } //Returns the name of the fields public String[] GetFieldNames(){ if(Bank){ String reply[] = new String[4]; reply[0] = "Date"; reply[1] = "Details"; reply[2] = "Transaction Amount"; reply[3] = "Transaction Type"; return(reply); } else{ String reply[] = new String[5]; reply[0] = "Date"; reply[1] = "Details"; reply[2] = "Num Shares"; reply[3] = "Share Price"; reply[4] = "Transaction Type"; return(reply); } } }