2016-04-03 10 views
-1

新しいat java。これはあなたの多くにとって愚かな質問かもしれません。 でも、私は迷惑だから助けてください。私がしようとしているものがあります。これらの2つのクラスを使用して私は覚えています。ここでJavaコードを定義しています。異なるオブジェクトから構成されたオブジェクトからの文字列配列の抽出

パブリッククラスの人々{

private int id, id100px; 
private String rollNumber; 
private String mobile_number, email_id, nick_name, hobbies, dob, name; 
private Testimony[] testimony; 


    public People(String name, int id, String mobile_number, String email_id, Testimony ... testimony) { 
     this.name = name; 
     this.id = id; 
     this.mobile_number = mobile_number; 
     this.email_id = email_id; 
     this.testimony = testimony; 
    } 

    public Testimony[] getTestimony() { 
     return testimony; 
    } 

    public String getEmail_id() { 
     return email_id; 
    } 

    public int getId() { 
     return id; 
    } 

    public String getMobile_number() { 
     return mobile_number; 
    } 

    public String getName() { 
     return name; 
    } 

} 

public class Testimony { 
    private String testimony; 
    private String name; 
    private int id; 

    public Testimony(String testimony,String name, int id){ 
     this.testimony = testimony; 
     this.id = id; 
     this.name = name; 
    } 

    public String gettestimony() { 
     return testimony; 
    } 

    public String getname() { 
     return name; 
    } 

    public int getid() { 
     return id; 
    } 

} 

は今、私は人々、クラス内のすべてのエントリのすべてのデータを抽出する必要があります。私はすべてのためにgetMethodsを使用しています。 I'am証言オブジェクトのデータの抽出と問題を抱えて、私が抽出し、1つの特定のオブジェクトや人々クラスの[]証言クラスの文字列の証言を保存する必要が

答えて

-1

証言はコンストラクタTestimony ... testimony内のvar argがあるので、あなたのようなゲッターを定義する必要が

:セッターのため

public Testimony[] getTestimony()(
} 

は同じロジックを適用することができます。

public void setTestimony(Testimony[] testimony){ 
    this.Testimony = testimony; 
} 

更新:

あなたがそれらを印刷する方法を定義することができ、すべての証言で情報が必要な場合:

public void printAllTestimonies(){ 
for (Testimony testim : testimony) { 
      System.out.println("Testimony: "+ testim.gettestimony()); 
      System.out.println("Name: "+ testim.getname()); 
      System.out.println("Id: "+ testim.getid()); 
     } 
} 
+0

をもう一度コードを見て、私は –

+0

完了更新をチェックして、私を聞かせて助けてください知ってください.... –

関連する問題