Skip to content
Snippets Groups Projects
Commit 5d244ab2 authored by vincent.steinman's avatar vincent.steinman
Browse files

Start order

parent fa995502
No related branches found
No related tags found
No related merge requests found
package org.example; package org.example;
import java.util.Arrays;
import java.util.Scanner; import java.util.Scanner;
public class Main { public class Main {
// static Person p1 = new Person("Doe", "John");
// static String[] phone = {"0"};
// static String[] social = {"S"};
// static String[] emails = {"a"};
// static Contact c1 = new Contact(p1, "jst", phone, emails, social, "j");
// static Contact c2 = new Contact(p1,"u",phone, emails,social, "NONE");
static Contact[] contactArray = {}; static Contact[] contactArray = {};
public static void main(String[] args) { public static void main(String[] args) {
while(true){ while(true){
...@@ -68,6 +63,7 @@ public class Main { ...@@ -68,6 +63,7 @@ public class Main {
System.arraycopy(contactArray,0,newContactArray, 0,size_array); System.arraycopy(contactArray,0,newContactArray, 0,size_array);
newContactArray[size_array] = c; newContactArray[size_array] = c;
contactArray = newContactArray; contactArray = newContactArray;
OrderArray();
} }
public static void Edit(){ public static void Edit(){
...@@ -184,4 +180,19 @@ public class Main { ...@@ -184,4 +180,19 @@ public class Main {
} }
return (nbInt < size_array); return (nbInt < size_array);
} }
public static void OrderArray(){
int size_array = contactArray.length;
Contact[] newContactArray = new Contact[size_array];
for(int i = 0; i < size_array -1; i++){
int test = contactArray[i].getPers().getFirst_name().compareTo(contactArray[i + 1].getPers().getFirst_name());
if(test < 0){
newContactArray[i] = contactArray[i+1];
newContactArray[i+1] = contactArray[i];
}
else{
newContactArray[i] = contactArray[i];
}
}
contactArray = newContactArray;
}
} }
\ No newline at end of file
...@@ -9,6 +9,14 @@ public class Person { ...@@ -9,6 +9,14 @@ public class Person {
this.first_name = first_name; this.first_name = first_name;
} }
public String getLast_name() {
return last_name;
}
public String getFirst_name() {
return first_name;
}
public void EditFirstName(String newFirstName){ public void EditFirstName(String newFirstName){
this.first_name = newFirstName; this.first_name = newFirstName;
} }
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment