java - Error in defining a selfmade superclass with subclasses -


i wrote abstract superclass distribution folows, contains constructor, , 2 methods.

public abstract class distribution {  public distribution(){}   public abstract void setparameters(hashmap<string,?> hm);   public abstract int getsample(); } 

hereafter, wrote 4 subclasses ( poisson, geometric, deterministic , binomial ). these subclasses same , this;

public class binomial extends distribution {     binomialdistribution distribution;     public binomial()    {        super();    }      @override     public void setparameters(hashmap<string,?> hm)     {     try     {          int n = 0;          double p =0.0;             if (hm.containskey("n"))                 if (hm.containskey("p"))                     p = double.parsedouble((string) hm.get("p"));                 else                      throw new exception("exception: no p-value found");             else                 throw new exception("exception: no n-value found");           distribution = new binomialdistribution(n,p);     }     catch(exception e)     {         system.out.println(e.getmessage());     }     }       @override     public int getsample()    {        return distribution.sample();     }    } 

in class want use these classes. want give hashmap distribution.setparameters method, , let program decide subclass fits parameters given in hashmap.

if want define distribution other class, doesn't seem work.

distribution arrivallength1distr = new distribution(); 

can tell me wrong , how problem solved ?

thanks !


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -