Here is my driver so far:
public class Driver extends javax.swing.JFrame {
Investment inv = new Investment();
Interest inter = new Interest();
String[] columnNames = {"Date", "Total", "Interest Earned"};
Object[][] rowData;
DefaultTableModel tableModel = new DefaultTableModel(rowData, columnNames);
DecimalFormat fmt1 = new DecimalFormat("0.00");
DecimalFormat fmt2 = new DecimalFormat("$,##0.00");
/** Creates new form Driver */
public Driver() {
initComponents();
jTable1.setModel(tableModel);
this.setLocationRelativeTo(null);
Calendar cal = new GregorianCalendar();
cal.set(2008, 2, 0, 0, 00);
Investment invest = new Investment("College Fund", 5000, 1000, 2.3, cal, 1);
nameDisplay.setText(invest.getName());
rateDisplay.setText(fmt1.format(invest.getRate()));
addInvestDisplay.setText(fmt2.format(invest.getAddI()));
inInvestDisplay.setText(fmt2.format(invest.getIniI()));
startDisplay.setText(cal.get(Calendar.MONTH) + "/" +
cal.get(Calendar.YEAR));
termDisplay.setText(Integer.toString(invest.getTerm()));
tableModel.addRow(new Object[] {cal.get(Calendar.MONTH) + "/" +
cal.get(Calendar.YEAR),
fmt2.format(invest.getIniI()), fmt2.format(115.0), true});
inter.annualInvestment();
}
public void addNewRow(Interest o)
{
tableModel.addRow(new Object[]{o.getDate(), o.getTempT(), o.getIntE()});
}
The object that I created is just for testing to make sure everything displays properly. There is a "New Investment" button on the frame to add a new investment.
Next, I have a class called Investment that is just used to create an Investment object.
public class Investment
{
private String name;
private double iniI;
private double rate;
private double addI;
private int term;
private Calendar date;
public Investment()
{
//No-arg Constructor//
}
public Investment
(String n, double iI,double aI, double r, Calendar dt, int t)
{
name = n;
iniI = iI;
addI = aI;
rate = r;
date = dt;
term = t;
}
public void setName(String n)
{
name = n;
}
public void setIniI(double iI)
{
iniI = iI;
}
public void setAddI(double aI)
{
addI = aI;
}
public void setRate(double r)
{
rate = r;
}
public void setDate(Calendar dt)
{
date = dt;
}
public void setTerm(int t)
{
term = t;
}
public String getName()
{
return name;
}
public double getIniI()
{
return iniI;
}
public double getAddI()
{
return addI;
}
public double getRate()
{
return rate;
}
public Calendar getDate()
{
return date;
}
public int getTerm()
{
return term;
}
}
And the last class is Interest. I was planning on this class to handle calculating the interest earned and pushing it back to Driver to display it in the jTable. I am having an issue with that right now, so if anyone can enlighten me as to way I keep getting "java.lang.OutOfMemoryError: Java heap space" when I run my program.
public class Interest
{
private Calendar date; //Date used to set loan start and for display//
private double tempT; //Temporary investement total for display//
private double tempI; //Used to display interest earned in a loop//
private double intE; //Interest earned//
private double invT; //Total investement return//
private double intI; //Interest for the first year to display in JTable//
private double startTot; //Used to start the total in the for loop//
public Interest()
{
//No-arg Constructor//
}
public Interest(Calendar d, double total, double iE)
{
date = d;
tempT = total;
intE = iE;
}
public double getTempT()
{
return tempT;
}
public double getIntE()
{
return intE;
}
public Calendar getDate()
{
return date;
}
public void annualInvestment()
{
Driver dr = new Driver();
Interest int2 = new Interest(date, 2000, 200);
dr.addNewRow(int2);
}
In the annualInvestment() method, I have it setup like this right now just trying to get it to work. You'll see in the Driver class there is method that is supposed to take the object created in Interest class and place it in a new row on the jTable. It's not working right now and I have no idea as to why. Thanks in advance for any advice someone can throw my way.

New Topic/Question
Reply




MultiQuote



|