|
-
November 23rd, 2008, 08:48 PM
#1
Creating an ArrayList as an attribute
Hello All,
Maybe it's time I started utilizing forums to help with my programs. I was assigned to create a program which connects to a database, access two tables, take information from the tables and store them as attributes of 2 objects. The only part that is hard for me is adding an ArrayList as an attribute. I am accessing a loan table and a payment table. Everything from the loan table is taken and assigned to the loan object and the payment table to payment object. The thing is every "loan" has payments. He wants us to add an ArrayList called "ArrayList<Payment>" to the loan class as an attribute of the loan object. I am having trouble creating an instance of this in my loan class... can anyone help? This assignment was already graded I just want to know how to do this for future reference (probably on my final exam as well). Thank you.
he's the loan class
Code:
import java.util.ArrayList;
public class Loan {
private String loanID; //id no
private String startDate; //date
private double annualRate; //loan annual rate
private double loanAmt; //loan amount due
private int noYears; //years on loan
private ArrayList<Payment> payments; //is this correct?
public Loan (String l, String s, double ar, double la, int ny, ArrayList<Payment> p)
{ loanID = l;
startDate = s;
annualRate = ar;
loanAmt = la;
noYears = ny;
ArrayList<Payment> payments = new ArrayList<Payment>(); //this doesn't work
/*public Loan ()
{ this.loanID= loanID;
this.startDate = startDate;
this.annualRate= annualRate;
this.loanAmt = loanAmt;
this.noYears = noYears;
ArrayList<Payment> = ArrayList<Payment>();
//ArrayList <Payment> payments = new ArrayList <Payment>();
*/
}//end loan constructor
public void setloanID (String l)
{
loanID = l;
}//end setloanID
public String getloanID ()
{
return loanID;
}//end getloanID
public void setstartDate (String s)
{
startDate = s;
}//end setstartDate
public String getstartDate ()
{
return startDate;
}//end getstartDate
public void setannualRate (double ar)
{
annualRate = ar;
}
public double getannualRate (double ar)
{
return annualRate;
}//end getstartDate
public void setloanAmt (double la)
{
loanAmt = la;
}
public double getloanAmt (double la)
{
return loanAmt;
}//end getstartDate
public void setnoYears (int ny)
{
noYears = ny;
}
public int getnoYears (int ny)
{
return noYears;
}//end getstartDate
public ArrayList <Payment> getPayments ()
{
return payments;
}//end getPayments
}//end loan
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|