2014-09-11 5 views
-2

나는 아직도 자바에 대한 신조어로서 나를 용서한다. 나는 9 개의 다른 클래스를 가지고있다. 내 계정 드라이버에서 일부 가짜 데이터를 넣을 수있는 메서드로드 데이터를 만들어야합니다.다른 클래스의 배열 목록에 값을 추가하는 방법은 무엇입니까?

내 생성자 이러한 값을 입력하는 방법을 알아낼 질수은 다음과 같습니다

public Account(Customer c,double b,Day d){ 
    cust = c; 
    balance= b; 
    dateOpened=d; 
    } 

public Customer(String last, String first) 
{ 
    this.last = last; 
    this.first=first; 
    custNum = nextNum; 
    nextNum++; 
} 

public Day(int yyyy, int m, int d) 
{ year = yyyy; 
    month = m; 
    day = d; 
    if (!isValid()) 
    throw new IllegalArgumentException(); 
} 

    public CheckingAccount(double mf,Customer c,double b,Day d){ 
    monthlyFee=mf; 
} 

public SavingsAccount(Customer c,double b,Day d,double i){ 

    intRate=i; 


} 

public SuperSavings(double mf,Customer c,double b,Day d,double m){ 
    minDeposit=m; 


} 

내 AccountDriver :

import java.util.ArrayList; 


public class AccountDriver { 

public static void main(String[] args){ 
    ArrayList<Customer> c = new ArrayList<Customer>(); 
ArrayList<Account> a = new ArrayList<Account>(); 
ArrayList<Day> d = new ArrayList<Day>(); 

    loadData(c,a,d); 
    print(a); 
} 

public static void loadData(ArrayList<Customer> c,ArrayList<Account> a, ArrayList<Day> d) { 

    a.add(new Account(new Customer("Sam", "Jones"),45000,new Day(2012,12,4))); 

} 

private static void print(ArrayList<Account> s) { 
    for (int i=0;i<s.size();i++) 
System.out.println(s.get(i).toString()); 
} 

}

+0

무엇을 하시겠습니까? 그 클래스의 모든 인스턴스를 동일한'ArrayList'에 넣으시겠습니까? 또는 다른'ArrayList's에 넣으시겠습니까? – Assaf

답변

0

당신은 모두를 만들어야합니다 필요한 인스턴스 :

Customer c = new Customer("John", "Doe"); 
Day day = new Day(2014, 9, 11); 
Account account = new Account(c, 1000D, day); 
// add the account 
List<Account> accounts = new ArrayList<>(); 
accounts.add(account); 
0
Account account = 
    new Account(new Customer("first name","last name"), 10.0d, new Day(2014,9,11)); 
0

생성자 메소드 서명과 일치하는 매개 변수를 전달해야합니다. 다음은 예입니다.

Customer customer = new Customer("Doe","John"); 
double balance = 1000.0; 
Day day = new Day(1992,4,20); 

a.add(new Account(customer, balance, day)); 
+0

나는 두 배가 d 배수가 필요하다고 생각했다. 배간 된 균형 = 1000.0d; – StackFlowed

관련 문제