diff --git a/src/input/Person.java b/src/input/Person.java index a8009a9..493b42d 100644 --- a/src/input/Person.java +++ b/src/input/Person.java @@ -1,5 +1,7 @@ package input; +import java.security.KeyStore; + public class Person implements Input{ public String lastName; public String firstName[]; @@ -61,6 +63,12 @@ public class Person implements Input{ @Override public boolean research(String search) { + if (lastName.equals(search)) + return true; + else + for (String s: firstName) + if (s.equals(search)) + return true; return false; } } diff --git a/src/input/Society.java b/src/input/Society.java index 3c5c291..6f6dbdf 100644 --- a/src/input/Society.java +++ b/src/input/Society.java @@ -15,6 +15,6 @@ public class Society implements Input{ @Override public boolean research(String search) { - return false; + return socialReason.equals(search); } } diff --git a/src/noteBook/NoteBook.java b/src/noteBook/NoteBook.java index 1c51645..2f54d32 100644 --- a/src/noteBook/NoteBook.java +++ b/src/noteBook/NoteBook.java @@ -1,8 +1,45 @@ package noteBook; import input.Input; +import input.Person; +import input.Society; public class NoteBook { - Input inputs[]; - Input selected[]; + public Input[] inputs; + public Input[] selected; + + public void addInput(Input in) { + Input[] tmp = new Input[inputs.length+1]; + System.arraycopy(inputs, 0, tmp, 0, inputs.length); + tmp[inputs.length] = in; + inputs = tmp; + } + + public void select(String selected) { + for (Input i: inputs) + if (i.toString().equals(selected)) { + this.selected = new Input[]{i}; + break; + } + } + + public void select(Input selected) { + this.selected = new Input[]{selected}; + } + + public void select(Input[] selected) { + this.selected = selected; + } + + public Input[] research(String target) { + Input[] tmp = new Input[inputs.length]; + int index = 0; + for (Input i: inputs) { + if (i.research(target)) + tmp[index++] = i; + } + Input[] out = new Input[index]; + System.arraycopy(tmp, 0, out, 0, out.length); + return out; + } } diff --git a/src/test/TestSelection.java b/src/test/TestSelection.java new file mode 100644 index 0000000..428421c --- /dev/null +++ b/src/test/TestSelection.java @@ -0,0 +1,13 @@ +package test; + +import input.Input; +import noteBook.NoteBook; + +public class TestSelection { + public static void main(String[] args) { + NoteBook book = new NoteBook(); + book.FileReading("testBook"); + for (Input i: book.inputs) + System.out.println(i); + } +}