diff --git a/Programmierung2/src/Übungen/Nacnhrichten.java b/Programmierung2/src/Übungen/Nacnhrichten.java deleted file mode 100644 index bb10f8a..0000000 --- a/Programmierung2/src/Übungen/Nacnhrichten.java +++ /dev/null @@ -1,28 +0,0 @@ -package Übungen; -import java.util.ArrayList; - -public class Nacnhrichten{ - - - public ArrayList nachrichtenlists; - - - public Nacnhrichten() { - - this.nachrichtenlists = new ArrayList<>(); - } - - - public void saveMessages(String nachricht){ - - nachrichtenlists.add(nachricht); - - - } - - public void printAllMessages() { - for(String mes: nachrichtenlists) - System.out.println(mes.toString()); - } - -} diff --git a/Programmierung2/src/Übungen/Whatsapp.java b/Programmierung2/src/Übungen/Whatsapp.java index 04fd52c..2d69cab 100644 --- a/Programmierung2/src/Übungen/Whatsapp.java +++ b/Programmierung2/src/Übungen/Whatsapp.java @@ -2,87 +2,48 @@ package Übungen; import java.util.ArrayList; public class Whatsapp { - protected String name; - protected String teleN; - protected String nachricht; - protected Whatsapp empf; - protected ArrayList speicherContact; - protected ArrayList speicherNummern; - protected ArrayList addGrouppe; - protected String grouppeName; - private Nacnhrichten nachrichten; + private String name; + private String teleN; + private String nachricht; + public ArrayList speicherContact; + private ArrayList speicherNummern; - public Whatsapp(String name, String teleN,Nacnhrichten nachrichten) { + public Whatsapp(String name, String teleN) { this.name = name; this.nachricht = null; this.teleN = teleN; - this.nachrichten = nachrichten; - this.empf = null; this.speicherContact = new ArrayList<>(); + speicherContact.add(this.name); this.speicherNummern = new ArrayList<>(); - this.addGrouppe = new ArrayList<>(); - this.grouppeName = null; + speicherNummern.add(teleN); } - public void sendeNachricht(Whatsapp empf , String nachricht) { - if (empf != null) { - this.empf = empf; - this.empf.setNachricht(nachricht); - String formattedMessage = this.name + " sendet an " + empf.getName() + ": " + empf.getNachricht(); - - nachrichten.saveMessages(formattedMessage); - } - else - System.err.println("Empfäbnger existitiert nicht!"); - } - - - public ArrayList addgrouppe(String grouppeName,ArrayList addGrouppe) { - this.addGrouppe.addAll(addGrouppe); - this.grouppeName = grouppeName; - - return addGrouppe; - } - - public void printgrouppe(){ - - System.out.println("Die Grouppe " + this.grouppeName ); - for (int i = 0; i < addGrouppe.size(); i++){ - System.out.println(addGrouppe.get(i)); - } - } public void addContact(String name, String teleN){ if (name != null && teleN != null){ speicherContact.add(name); speicherNummern.add(teleN); } - - } - - public String searchContact(String name){ - for (int i = 0; i getContact(){ return this.speicherContact; } public void printContacte(){ System.out.println("Deine KontaktListe: "); - for (int i = 0; i < speicherContact.size(); i++){ - System.out.println("Name: " + speicherContact.get(i) + ", Telefonnummer: " + speicherNummern.get(i)); - } + + for (int i = 0; i < speicherContact.size();i++) + System.out.println("Name: " + speicherContact.get(i) +", Telefonummer: " + speicherNummern.get(i)); + } - - - - + public String searchContact(String name){ + for (int i = 0; i saveMessages; + + public Nachrichten(Whatsapp sender, Whatsapp receiver) { + + this.sender = sender; //obai + this.receiver = receiver; //omar + this.saveMessages = new ArrayList<>(); + } + + public void sendMessage(Whatsapp sender,Whatsapp receiver ,String message) { + + if (receiver != null) { + String infoMessage = sender.getName() + " sendet " + receiver.getName() +" : " + message; + saveMessages.add(infoMessage); + }else + System.out.println("User does not exist"); + } + + public ArrayList getinfoMessage() { + return saveMessages; + } + + public void printsaveMessages() { + System.out.println("Chat Room: "); + for(String s:saveMessages) + System.out.println(s); + } + +} + +class Groups{ + Whatsapp hersteller; + ArrayList admins; + ArrayList addmembers; + String groupsname; + + + Groups(Whatsapp hersteller, String groupsname){ + this.hersteller = hersteller; + this.groupsname = groupsname; + this.addmembers = new ArrayList<>(); + this.admins = new ArrayList<>(); + addmembers.add(hersteller); + admins.add(hersteller); + System.out.println(this.hersteller.getName() + "(Admin): hat die Groupe " + this.groupsname + " erstellt"); + } + + public void removeMemebr(Whatsapp remover, Whatsapp toBeRemoved) { + if (!admins.contains(remover)) { + System.err.println("Du bist kein Admin"); + return; + }else + addmembers.remove(toBeRemoved); + + } + + public void addMembers(Whatsapp member) { + if (!addmembers.contains(member)) + addmembers.add(member); + else + System.err.println("member ist bereits da!"); + } + + public void addAdmin(Whatsapp admin,Whatsapp toBeAdmin) { + if (admins.contains(admin)){ + this.admins.add(toBeAdmin); + System.out.println(admin.getName() + " hat " + toBeAdmin.getName() + " als Admin gennengezichnet"); + } + else + System.err.println("Du musst Admin sein"); + } + + public ArrayList getaddmembers(){ + + return addmembers; + } + + public void printaddmembers(Whatsapp printer) { + if (!addmembers.contains(printer)) { + System.err.println("du bist kein Mitglied!"); + return; + } + + System.out.println("Alle Members:"); + int i = 1; + for (Whatsapp s : addmembers) { + String memberName = printer.speicherContact.contains(s.getName()) ? s.getName() : "Unbekannt"; + + if (admins.contains(s)) + System.out.println("Mitglied(Admin) " + i + " : " + memberName); + else + System.out.println("Mitglied " + i + " : " + memberName); + + + i++; + } + + } + + + } + diff --git a/Programmierung2/src/Übungen/WhatsappTest.java b/Programmierung2/src/Übungen/WhatsappTest.java index aa44291..33227a2 100644 --- a/Programmierung2/src/Übungen/WhatsappTest.java +++ b/Programmierung2/src/Übungen/WhatsappTest.java @@ -4,18 +4,32 @@ import java.util.ArrayList; public class WhatsappTest { public static void main(String[] args) { - Nacnhrichten nachrichten = new Nacnhrichten(); + Whatsapp obai = new Whatsapp("obai", "049321384324"); + Whatsapp omar = new Whatsapp("omar", "049321384324"); + Whatsapp abd = new Whatsapp("abd", "049321321"); + Whatsapp oula = new Whatsapp("oula", "049321321"); - Whatsapp obai = new Whatsapp("obai", "049321384324",nachrichten); - Whatsapp omar = new Whatsapp("Omar", "049321384324",nachrichten); - obai.sendeNachricht(omar, "hallo Omar"); - omar.sendeNachricht(obai, "hallo Obai"); - obai.sendeNachricht(omar, "was machst du?"); - omar.sendeNachricht(obai, "nix und du"); - nachrichten.printAllMessages(); - - +// Nachrichten messages = new Nachrichten(obai,omar); +// messages.sendMessage(obai, omar, "Hallo Omar"); +// messages.sendMessage(omar, obai, "Hallo Obai"); +// messages.sendMessage(omar, obai, "was machst du?"); +// messages.printsaveMessages(); + + Groups gr1 = new Groups(obai,"Almidani"); + gr1.addMembers(omar); + gr1.addMembers(abd); + + obai.addContact("abd","004848214"); + obai.addContact("omar","004848214"); + gr1.addAdmin(obai, omar); + gr1.printaddmembers(obai); + System.out.println(); + System.out.println(); + System.out.println(); + gr1.printaddmembers(omar); + + } }