Skip to content
Snippets Groups Projects
MampfMobil.java 5.25 KiB
Newer Older
  • Learn to ignore specific revisions
  • fheyming's avatar
    fheyming committed
    package com.example.mampfmobil.ui;
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import android.util.Log;
    
    
    fheyming's avatar
    fheyming committed
    import com.example.mampfmobil.ui.Classes.Bestellung;
    import com.example.mampfmobil.ui.Classes.BestellungsTeil;
    import com.example.mampfmobil.ui.Classes.Customer;
    import com.example.mampfmobil.ui.Classes.Deliverer;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    import com.example.mampfmobil.ui.Classes.Item;
    import com.example.mampfmobil.ui.Classes.ShopItem;
    
    fheyming's avatar
    fheyming committed
    import com.example.mampfmobil.ui.Classes.Supplier;
    
    import java.util.Vector;
    
    public class MampfMobil {
    
        public static Vector<Customer> customers;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static Customer currentCustomer;
    
    fheyming's avatar
    fheyming committed
        public static Vector<Deliverer> deliverers;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static Deliverer currentDeliverer;
    
    fheyming's avatar
    fheyming committed
        public static Vector<Supplier> suppliers;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static Supplier currentSupplier;
    
    fheyming's avatar
    fheyming committed
    
    
        public static boolean isInitialized = false;
    
        public MampfMobil(){
            if(!isInitialized) {
                customers = new Vector<>();
                deliverers = new Vector<>();
                suppliers = new Vector<>();
    
                //create Dummys!!!
                customers.add(new Customer("", "", ""));
                deliverers.add(new Deliverer("", "", ""));
                suppliers.add(new Supplier("", ""));
                customers.add(new Customer("Fabio", "Heyming", "Weinbergstr 70, 55299 Nackenheim"));
                customers.add(new Customer("Leah", "Iilyav", "Bad Homburg"));
                customers.add(new Customer("Max", "Muster", "Musteradresse"));
                deliverers.add(new Deliverer("Mr", "Fahrer", "Fahrstr."));
                deliverers.add(new Deliverer("Mrs", "Fahrerin", "Fahrstr."));
                suppliers.add(new Supplier("DummyShop", "Dummystreet"));
    
    fheyming's avatar
    fheyming committed
                suppliers.add(new Supplier("FreeShop", "Freeadress"));
    
                suppliers.add(new Supplier("Rewe", "Rewestr"));
    
    fheyming's avatar
    fheyming committed
                suppliers.get(0).itemAdd("DummyApfel", 10, 0.5);
                suppliers.get(0).itemAdd("DummyBanane", 5, 0.8);
                suppliers.get(0).itemAdd("DummyBirne", 10, 0.5);
                suppliers.get(0).itemAdd("DummyAnanas", 5, 0.8);
    
                suppliers.get(1).itemAdd("DummyApfel", 10, 0.5);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                suppliers.get(1).itemAdd("DummyBanane", 5, 0.8);
    
                suppliers.get(2).itemAdd("FreeApfel", 5, 3.4);
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                suppliers.get(2).itemAdd("FreeBanane", 5, 5.8);
                /*Bestellung temp = new Bestellung();
    
                temp.addBestellungsteil(new BestellungsTeil(suppliers.get(1).shopItems.get(0).item, 5));
                temp.addBestellungsteil(new BestellungsTeil(suppliers.get(2).shopItems.get(1).item, 10));
                customers.get(0).addBestellung(temp);
                Bestellung temp2 = new Bestellung();
                temp.addBestellungsteil(new BestellungsTeil(suppliers.get(1).shopItems.get(1).item, 7));
                temp.addBestellungsteil(new BestellungsTeil(suppliers.get(2).shopItems.get(0).item, 14));
    
    Fabio Heyming's avatar
    Fabio Heyming committed
                customers.get(1).addBestellung(temp);*/
    
                isInitialized = true;
            }
    
    fheyming's avatar
    fheyming committed
        }
    
    Fabio Heyming's avatar
    Fabio Heyming committed
    
        public static boolean findCustomer(String vorname, String nachname){
            for(Customer c:customers){
                if(c.vorname.equals(vorname) && c.nachname.equals(nachname)){
                    MampfMobil.currentCustomer = c;
                    return true;
                }
            }
            return false;
        }
    
        public static boolean createCustomer(String vorname, String nachname,String adresse){
            for(Customer c:customers){
                if(c.vorname.equals(vorname) && c.nachname.equals(nachname)){
                    return false;
                }
            }
    
            Customer temp = new Customer(vorname,nachname,adresse);
            customers.add(temp);
            currentCustomer = temp;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            return true;
        }
    
        public static boolean findSupplier(String name){
            for(Supplier s:suppliers){
                if(s.name.equals(name)){
                    MampfMobil.currentSupplier = s;
                    return true;
                }
            }
            return false;
        }
    
        public static boolean createSupplier(String name,String address){
            for(Supplier s:suppliers){
                if(s.name.equals(name)){
                    return false;
                }
            }
    
            Supplier temp = new Supplier(name,address);
            suppliers.add(temp);
            currentSupplier = temp;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            return true;
        }
        public static boolean findDeliverer(String vorname, String nachname){
            for(Deliverer d:deliverers){
                if(d.vorname.equals(vorname) && d.nachname.equals(nachname)){
                    MampfMobil.currentDeliverer = d;
                    return true;
                }
            }
            return false;
        }
    
        public static boolean createDeliverer(String vorname, String nachname,String address){
            for(Deliverer d:deliverers){
                if(d.vorname.equals(vorname) && d.nachname.equals(nachname)){
                    return false;
                }
            }
    
    
            Deliverer temp = new Deliverer(vorname,nachname,address);
            deliverers.add(temp);
            currentDeliverer=temp;
    
    Fabio Heyming's avatar
    Fabio Heyming committed
            return true;
        }
    
    
    Fabio Heyming's avatar
    Fabio Heyming committed
        public static int getItemQuantity(Item item){
            for(Supplier s:suppliers){
                for(ShopItem sI: s.shopItems){
                    if(sI.item == item){
                        return sI.quantity;
                    }
                }
            }
            return 0;
        }
    
    
    fheyming's avatar
    fheyming committed
        public static int value = 10;
        public static int getVall(){
            return value;
        }
        public static void setVall(int i){
            value = i;
        }
    
    }