java - Passing an array of Strings from inside a Static Function in a different class to another class -


i trying arrays 't','p' , 's' class 'buildorder' class. here code reference:

i tried create methods return them , retrieve them in class out of ideas how it. trying add decorator pattern base code of composite pattern component here interface composite pattern

package composite;  public class buildorder {  public static component getorder() {     composite order = new composite( "order" ) ;     order.addchild(new leaf("crispy onion strings", 5.50 ));     order.addchild(new leaf("the purist", 8.00 ));     //composite customburger = new composite( "build own burger" ) ;       string[] t={"bermuda red onion","black olives","carrot           strings","coleslaw"};      string[] p={"applewood smoked bacon"};      string[] s={"apricot sauce"};      /*customburger.addchild(new leaf("beef, 1/3 lb on bun",9.50 )); // base price 1/3 lb     customburger.addchild(new leaf("danish blue cheese", 0.00 )); // 1 cheese free, cheese +1.00     customburger.addchild(new leaf("horseradish cheddar", 1.00 )); // cheese +1.00     customburger.addchild(new leaf("bermuda red onion", 0.00 )); // 4 toppings free, +.75     customburger.addchild(new leaf("black olives", 0.00 )); // 4 toppings free, +.75     customburger.addchild(new leaf("carrot strings", 0.00 )); // 4 toppings free, +.75     customburger.addchild(new leaf("coleslaw", 0.00 )); // 4 toppings free, +.75     customburger.addchild(new leaf("applewood smoked bacon", 1.50 )); // premium topping +1.50     customburger.addchild(new leaf("apricot sauce", 0.00  )); // 1 sauce free, +.75     order.addchild( customburger );*/     return order ;  }     public string[] gettoppings()     { return t;     }      public string[] getpremium()     { return p;     }     public string[] getsauces()     { return s;     } }  //following class want use above strings  public class sauce implements leafdecorator { public string sauce() {   buildorder bo=new buildorder();     string[] order=bo.getsauces(string[] s);  } } 

there appears more 1 mismatch in example.

you define class variables...

string[] t; string[] p; string[] s; 

but define them again within getorder() method -- covering class-level variables within scope of method.

note: way have them, these variables package-private (default access specifier). go private.

the methods gettoppings, getpremium, , getsauces (inside buildorder class) pointless -- return passed.

the class sauce doesn't compile. should compile (depending on leafdecorator)...

public class sauce implements leafdecorator {      public string sauce() {         buildorder bo = new buildorder();         string order = bo.getsauces("some string -- what's for?");     }  } 

the order string equal "some string -- what's for?".


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -