This is my Data class:
public class Data {
private String name;
private int age;
Data(String n,int a){
name = n;
age = a;
}
public String getName(){
return(name);
}
public void setName(String n){
name = n;
}
public int getAge(){
return(age);
}
public void setAge(int a){
age = a;
}
public void Print(){
System.out.print(("("+GetName()));
System.out.print(",");
System.out.print(GetAge());
System.out.print(") ");
}
}
This is my CS1702_Lab5 class that uses ArrayList and that is supposed to print the content of ArrayList:
import java.util.ArrayList;
public class CS1702_Lab5 {
public static void main(String args[]){
ArrayList<Data> data = new ArrayList<Data>();
data.add(new Data("Fred", 21));
}
private static void PrintDataArray(ArrayList<Data> data) {
for(int i=0;i<data.size();++i){
data.get(i).Print();
}
}
}
I am trying to add new Data which is a StringName and IntAge and then display it but it doesn't seem to work. The console is empty nothing is printed.
Thank you in advance!