2016-04-03 18 views
-1

java'da yeniyim. Bu, çoğunuz için aptalca bir soru olabilir. Ama ben Struck'um, lütfen yardım edin. Yapmaya çalıştığım bir şey var. Aşağıdaki iki sınıfı kullanıyorum. Burada java kodlarını tanımlarım.Farklı Nesne'den Oluşan Diziden Dize Dizisi Ekstraksiyonu

public class İnsanlar {

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; 
    } 

} 

ve

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; 
    } 

} 

Şimdi, insanlar Sınıf her giriş için her veri ayıklamak gerekiyor. Her şey için getMethods kullanıyorum. bi'şey Tanıklık Nesne için veri çıkarımı ile sorun yaşıyorsanız, ben ayıklamak ve yalnızca belirli bir nesne veya Kişiler Sınıfı [] Tanıklık sınıfının dize ifadesini kaydetmeniz gerekir

cevap

-1

Tanıklık yapıcı Testimony ... testimony bir var arg olduğundan

public void setTestimony(Testimony[] testimony){ 
    this.Testimony = testimony; 
} 
: aynı mantık uygulayabilirsiniz setter için

public Testimony[] getTestimony()(
} 

:

sen gibi bir alıcı tanımlamak zorunda


Güncelleme: her Tanıklık içinde bilgi gerekiyorsa

o baskı için bir yöntem tanımlayabilirsiniz:

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

tekrar kodunu görmek ve beni –

+0

bitti güncelleştirme kontrol yardımcı olabilir ve lütfen içeri biliyorum lütfen .... –