Thanks for you answer but it did not work for me.
File name is called Addressbook store in sketch folder.
Class Name Addressbook
When I save Addressbook.pde as Addressbook.java An error like this:
The sketch name had to be modified. Sketch names can only consist of ASCII characters and numbers (but cannot start with a number). They should also be less than 64 characters long.
And the new filename named Addressbook_java gets created.
here is mine class:
class Addressbook{
private int id;
private String name;
public Addressbook(
int id,
String name) {
this.name = name;
this.id = id;
}
public String toString() {
return id + " { " + name;
}
public String getName() {
return name;
}
public int getID() {
return id;
}
}
class Adressbook {
private String name;
private Addressbook[] contacts;
public Adressbook(String name) {
this.name = name;
this.contacts = new Addressbook[0];
}
public String showAll() {
String output = "Adressbuch { " +name +"\n";
for (int i = 0; i < contacts.length; i++) {
output = output + contacts[i].toString() + "\n";
}
return output;
}
public String showByName(String name) {
for (int i = 0; i < contacts.length; i++) {
if (contacts[i].getName() == name) {
return contacts[i].toString();
}
}
return "";
}
public void addContact(Addressbook contact) {
Addressbook[] contactsNew = new Addressbook[contacts.length + 1];
for (int i = 0; i < contacts.length; i++) {
contactsNew[i] = contacts[i];
}
contactsNew[contactsNew.length -1] = contact;
contacts = contactsNew;
}
public Addressbook getContact(int id) {
for (int i = 0; i < contacts.length; i++) {
if (contacts[i].getID() == id) {
return contacts[i];
}
}
return null;
}
public void removeContact(int id) {
Addressbook[] contactsCopy = new Addressbook[0];
for (int i = 0; i < contacts.length; i++) {
if (contacts[i].getID() != id) {
Addressbook[] contactsCopyNew = new Addressbook[contactsCopy.length +1];
for (int j = 0; j < contactsCopy.length; j ++) {
contactsCopyNew[j] = contactsCopy[j];
}
contactsCopyNew[contactsCopyNew.length -1] = contacts[i];
contactsCopy = contactsCopyNew;
}
}
this.contacts = contactsCopy;
}
}
and the new sketch
import Addressbook;
public void setup() {
Adressbook privat = new Adressbook("Privat");
privat.addContact(new Contact(1, "ken Tern"));
privat.addContact(new Contact(2, "jlkjlldk"));
privat.addContact(new Contact(3, "lkjljlkj"));
print(privat.showAll());
}
I know you me using without import but this did also not work.