I'm having a small issue with this program. It's an appointment book, and the idea is to be able to add contacts and events.
Here is the first part of my code and the one I'm having trouble with:
String aux = " ";
String aux2 = " ";
long aux3 = 0;
Arraylist <Person> cole1 = new Arraylist();
do{
System.out.println("Welcome");
System.out.println("- Book");
System.out.println("1. Add contact");
System.out.println("2. See contacts");
System.out.println("3. Remove contacts");
switch(Integer.parseInt(teclado.readLine())){
case 1:
for(int i = 0; i<cole1.size();i++){
System.out.println("Write the name");
aux = teclado.readLine();
System.out.println("Write the email");
aux2 = teclado.readLine();
System.out.println("Write the phone number");
aux3 = Integer.parseInt(teclado.readLine());
cole1.add(new Person(aux, aux2, aux3));
}
break;
default:
System.out.println("error");
break;
}
}while(true);
Here's my person class:
public class Person {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public float getNum() {
return num;
}
public void setNum(long num) {
this.num = num;
}
private String name;
private String email;
private long num;
public Persona(String n, String e, long nu){
this.name=n;
this.email=e;
this.num=nu;
}
}
This part should be able to create a new person with the name, phone and email attributes. The problem is when I press 1 in my switch for the add option i get the following error:
Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
at agenda.Arraylist.size(Arraylist.java:15)
at agenda.AgendaTest.main(AgendaTest.java:40)
C:\Users\melis\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)
I can't figure out if its a logic or syntax problem. I've read a few other questions with people having a similar problem. The difference is, all of them where apparently using the Arrays.asList property, which if i understand correctly, Arrays.asList doesn't support add/remove operations.
Any idea on what is going wrong?
Thanks in advance! And sorry if my English is bad.
Arraylistclass?