updates für Chat
parent
898277c351
commit
29b1d0cf27
|
@ -1,28 +0,0 @@
|
|||
package Übungen;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Nacnhrichten{
|
||||
|
||||
|
||||
public ArrayList<String> 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());
|
||||
}
|
||||
|
||||
}
|
|
@ -2,62 +2,39 @@ package Übungen;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class Whatsapp {
|
||||
protected String name;
|
||||
protected String teleN;
|
||||
protected String nachricht;
|
||||
protected Whatsapp empf;
|
||||
protected ArrayList <String> speicherContact;
|
||||
protected ArrayList <String> speicherNummern;
|
||||
protected ArrayList <Whatsapp> addGrouppe;
|
||||
protected String grouppeName;
|
||||
private Nacnhrichten nachrichten;
|
||||
private String name;
|
||||
private String teleN;
|
||||
private String nachricht;
|
||||
public ArrayList <String> speicherContact;
|
||||
private ArrayList <String> 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<Whatsapp> addgrouppe(String grouppeName,ArrayList<Whatsapp> 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 ArrayList<String> 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) +", Telefonummer: " + speicherNummern.get(i));
|
||||
|
||||
}
|
||||
|
||||
|
@ -68,22 +45,6 @@ public class Whatsapp {
|
|||
return "Der Name exesitert nicht!";
|
||||
}
|
||||
|
||||
public ArrayList<String> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -109,3 +70,110 @@ public class Whatsapp {
|
|||
return "Whatsapp [name=" + name + ", teleN=" + teleN + "]";
|
||||
}
|
||||
}
|
||||
|
||||
// nachrichten zwischen zwei Usern
|
||||
class Nachrichten{
|
||||
Whatsapp sender;
|
||||
Whatsapp receiver;
|
||||
ArrayList<String> 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<String> getinfoMessage() {
|
||||
return saveMessages;
|
||||
}
|
||||
|
||||
public void printsaveMessages() {
|
||||
System.out.println("Chat Room: ");
|
||||
for(String s:saveMessages)
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Groups{
|
||||
Whatsapp hersteller;
|
||||
ArrayList<Whatsapp> admins;
|
||||
ArrayList<Whatsapp> 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<Whatsapp> 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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,16 +4,30 @@ 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);
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue