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

Export/Import

parent 2c8b12a7
No related branches found
No related tags found
No related merge requests found
Family
Fam 1 /Fam 2/Fam 3/Fam 4 /Fam 5 /Fam 6 /Fam 7/Bro
Professional
Pro 1 /Pro 2/Pro 3/Pro 4 /Pro 5 /Pro 6 /Pro 7/Work
Friend
Vincent /Steinmann/Ici/Num /Mail /Social /Job
\ No newline at end of file
...@@ -118,7 +118,7 @@ public abstract class Contact implements Comparable<Contact>{ ...@@ -118,7 +118,7 @@ public abstract class Contact implements Comparable<Contact>{
w_social += elem + " "; w_social += elem + " ";
} }
return w_names + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" return w_names + "\n" + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n"
+ w_social + "\n" + this.job; + w_social + "\n" + this.job;
} }
@Override @Override
......
...@@ -11,6 +11,10 @@ public class Family extends Contact{ ...@@ -11,6 +11,10 @@ public class Family extends Contact{
this.relation = relation; this.relation = relation;
} }
public String getRelation() {
return relation;
}
@Override @Override
public String toString(){ public String toString(){
String w_names = ""; String w_names = "";
...@@ -31,7 +35,7 @@ public class Family extends Contact{ ...@@ -31,7 +35,7 @@ public class Family extends Contact{
w_social += elem + " "; w_social += elem + " ";
} }
return w_names + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" return w_names + "\n" + this.last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n"
+ w_social + "\n" + this.job + "\n" + this.relation; + w_social + "\n" + this.job + "\n" + this.relation;
} }
} }
...@@ -37,7 +37,7 @@ public class Main { ...@@ -37,7 +37,7 @@ public class Main {
Export(contactArray); Export(contactArray);
break; break;
case "6": case "6":
//Import(contactArray); Import(contactArray);
break; break;
default: default:
System.out.println("Please enter valid input"); System.out.println("Please enter valid input");
...@@ -280,8 +280,18 @@ public class Main { ...@@ -280,8 +280,18 @@ public class Main {
try{ try{
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
for (Contact c: ca){ for (Contact c: ca){
List<String> str_array = SplitLine(c.toString(), "\n");
writer.write(c.get_type() + "\n"); writer.write(c.get_type() + "\n");
writer.write(c.getFirst_name() + "\n"); writer.write(str_array.get(0) + "/");
writer.write(str_array.get(1) + "/");
writer.write(str_array.get(2) + "/");
writer.write(str_array.get(3) + "/");
writer.write(str_array.get(4) + "/");
writer.write(str_array.get(5) + "/");
writer.write(str_array.get(6));
if(c.get_type().equals("Family") || c.get_type().equals("Professional")){
writer.write("/" + str_array.get(7) + "\n");
}
} }
writer.close(); writer.close();
} catch (IOException e){ } catch (IOException e){
...@@ -291,21 +301,37 @@ public class Main { ...@@ -291,21 +301,37 @@ public class Main {
//TODO find good way to save //TODO find good way to save
//Warning list //Warning list
//Type of contact //Type of contact
// public static void Import(ArrayList<Contact> ca){ public static void Import(ArrayList<Contact> ca){
// System.out.println("Enter save file name"); System.out.println("Enter save file name");
// Scanner myObj = new Scanner(System.in); Scanner myObj = new Scanner(System.in);
// String fileName = myObj.nextLine(); String fileName = myObj.nextLine();
// try{ try{
// BufferedReader reader = new BufferedReader(new FileReader(fileName)); BufferedReader reader = new BufferedReader(new FileReader(fileName));
// String line; String line;
// while((line = reader.readLine()) != null){ int checker = 0;
// AddContactToList(line); while((line = reader.readLine()) != null){
// } switch (line){
// reader.close(); case "Friend":
// } catch (IOException e){ checker = 1;
// e.printStackTrace(); break;
// } case "Family":
// } checker = 2;
break;
case "Professional":
checker = 3;
break;
default:
List<String> str_array = SplitLine(line, "/");
AddContactToList(str_array, checker);
checker = 0;
break;
}
}
reader.close();
} catch (IOException e){
e.printStackTrace();
}
}
//Test if the value is a number or not and if it's withing the range of the list //Test if the value is a number or not and if it's withing the range of the list
public static boolean TryNumber(String nb){ public static boolean TryNumber(String nb){
int size_array = contactArray.size(); int size_array = contactArray.size();
...@@ -319,16 +345,73 @@ public class Main { ...@@ -319,16 +345,73 @@ public class Main {
return (nbInt < size_array); return (nbInt < size_array);
} }
// public static void AddContactToList(Contact c,String str){ public static void AddContactToList(List<String> str_array, int checker){
// int cpt = 1; switch (checker){
// switch (cpt){ case 1:
// case 1: ImportFriend(str_array);
// c.setFirst_name break;
// cpt++; case 2:
// break; ImportFamily(str_array);
// case 2: break;
// cpt++; case 3:
// break; ImportProfessional(str_array);
// } break;
// } default:
System.out.println("Error contact type");
break;
}
}
public static void ImportFriend(List<String> str_array){
Friend f = new Friend(
SplitArray(str_array.get(0)),
str_array.get(1),
str_array.get(2),
SplitArray(str_array.get(3)),
SplitArray(str_array.get(4)),
SplitArray(str_array.get(5)),
str_array.get(6)
);
Add(f);
}
public static void ImportFamily(List<String> str_array){
Family f = new Family(
SplitArray(str_array.get(0)),
str_array.get(1),
str_array.get(2),
SplitArray(str_array.get(3)),
SplitArray(str_array.get(4)),
SplitArray(str_array.get(5)),
str_array.get(6),
str_array.get(7)
);
Add(f);
}
public static void ImportProfessional(List<String> str_array){
Professional f = new Professional(
SplitArray(str_array.get(0)),
str_array.get(1),
str_array.get(2),
SplitArray(str_array.get(3)),
SplitArray(str_array.get(4)),
SplitArray(str_array.get(5)),
str_array.get(6),
str_array.get(7)
);
Add(f);
}
public static List<String> SplitLine(String str, String splitter){
List<String> data = Arrays.asList(str.split(splitter));
return data;
}
public static List<String> SplitArray(String str){
//str = str.substring(1, str.length() - 1);
String new_str = "";
for(char c: str.toCharArray()){
if(c !='[' && c !=']'){
new_str += c;
}
}
List<String> names = Arrays.asList(new_str.split(","));
return names;
}
} }
\ No newline at end of file
package org.example;
public class Person {
private String last_name;
private String first_name;
public Person(String last_name, String first_name){
this.last_name = last_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){
this.first_name = newFirstName;
}
public void EditLastName(String newLastName){
this.last_name = newLastName;
}
@Override
public String toString() {
return this.first_name + " " + this.last_name;
}
}
...@@ -10,7 +10,9 @@ public class Professional extends Contact{ ...@@ -10,7 +10,9 @@ public class Professional extends Contact{
super("Professional", first_name, last_name, addr, phone, email, social, job); super("Professional", first_name, last_name, addr, phone, email, social, job);
this.work_place = work_place; this.work_place = work_place;
} }
public String getWork_place() {
return work_place;
}
@Override @Override
public String toString(){ public String toString(){
String w_names = ""; String w_names = "";
...@@ -31,7 +33,7 @@ public class Professional extends Contact{ ...@@ -31,7 +33,7 @@ public class Professional extends Contact{
w_social += elem + " "; w_social += elem + " ";
} }
return w_names + last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n" return w_names + "\n" + last_name + "\n" + this.addr + "\n" + w_phone + "\n" + w_email + "\n"
+ w_social + "\n" + this.job + "\n" + this.work_place; + w_social + "\n" + this.job + "\n" + this.work_place;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment