public class Persons {
int id;//persons id
String name;//persons name
String email;//persons email
public Persons(int idNum, String student, String eAddress){
this.id = idNum;
this.name = student;
this.email = eAddress;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Id number
* @return integer of the id
*/
public int getId(){
return id;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* name of person
* @return string of the name
*/
public String getName(){
return name;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Email address for person
* @return string of the email
*/
public String getEmail(){
return email;
}
}
這是人類與3件數據。我不確定如何處理您問題中的其他數據。不確定它是否相關。以下是測試儀類。
import java.util.ArrayList;
public class Tester{
public static void main(String[] args){
Persons philip = new Persons(1, "Philip", "[email protected]");
Persons steve = new Persons(2, "Steve", "[email protected]");
Persons samatha = new Persons(3, "Samatha", "samathaemail.com");
ArrayList<Persons> list = new ArrayList<>();
list.add(philip);
list.add(steve);
list.add(samatha);
for(int i=0;i<3;i++){
System.out.println("ID number: " + list.get(i).getId());
System.out.println("Name: " + list.get(i).getName());
System.out.println("Email: " + list.get(i).getEmail());
}
}
}
然後創建以下輸出。
ID號:1 名稱:菲利普 電子郵件:[email protected] ID號:2 名稱:史蒂夫 電子郵件:[email protected] ID號:3 名稱:奢摩他 電子郵件:samathaemail .com
做你自己的功課。堆棧溢出不會爲你寫。 –
請參閱[給有功課問題的學生打開信件](http://meta.softwareengineering.stackexchange.com/q/6166)。 –