這幾年,因爲我居然花了編程類。我知道我可以做我想到的事情,但我不記得這些條款,所以我不能查找它。忘記術語
我寫了HMI類模擬應用。它訂購比薩餅。現在,我使用一個單獨的類來傳遞活動之間的比薩值。 (值如澆頭,比薩大小等)。該類名爲pizzaApplication.class,示例值爲pizzaApplication.chkPepperoni = true;
現在設置它的方式,我只能有一個比薩餅。我希望能夠讓pizzaApplication類設置多個比薩餅。然後(從內存中)的代碼最終會尋找類似
pizzaApplication.pizzaOne(chkPepperoni = true);
於是,兩個問題:
,這是什麼
什麼是增加不同的對象我會做的最好辦法確切的術語?即
pizzaApplication.pizzaOne(chkPepperoni = true);
或
pizzaApplication.pizza.1(chkPepperoni = true);
編輯:
爲了進一步澄清,我正在寫一個Android應用程序。我先問他們,使他們的選擇,他們的比薩餅,並把它們保存到一個不同的Java文件,命名爲PizzaApplication.java這裏是第一行代碼。
public class PizzaApplication extends Application {order_order order = new Order();
//private final String[] toppings = new String[] { "Pepperoni", "Onion",
// "Sausage", "etc." };
public PizzaApplication() {
}
//Booleans for checking whether the individual pages have been completed.
Boolean vfTop = false;
Boolean vfAdd = false;
Boolean vfBill = false;
//Booleans for whether to add toppings
Boolean cheese = false;
Boolean italian = false;
Boolean pineapple = false;
Boolean ham = false;
Boolean pepperoni = false;
Boolean chicken = false;
//Globally accessible storage strings for various things
public String creditCard = "none";
public String crustType = "";
public String addressLine1 = "";
public String addressLine2 = "";
public String phoneNumber = "";
public String Toppings = "";
public Integer pizzaCount;
public String pizzaSize = "";
現在,這裏是一些來自Toppings類的示例代碼。
public class Toppings_Page extends Activity {
PizzaApplication pizzaApplication;
CheckBox Cheese, Ham, Italian, Pepperoni, Chicken, Pineapple;
Integer intpizzaCount;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_toppings__page);
pizzaApplication = (PizzaApplication) getApplication();
Cheese = (CheckBox)findViewById(R.id.chkCheese);
Italian = (CheckBox)findViewById(R.id.chkItalian);
Ham = (CheckBox)findViewById(R.id.chkHam);
Pepperoni = (CheckBox)findViewById(R.id.chkPepperoni);
Chicken = (CheckBox)findViewById(R.id.chkChicken);
Pineapple = (CheckBox)findViewById(R.id.chkPinapple);
和一點點進一步下跌該類
public void onChecked(View view){
if (Cheese.isChecked()){pizzaApplication.cheese=true;}
else {pizzaApplication.cheese = false;}
if (Italian.isChecked()){pizzaApplication.italian=true;}
else {pizzaApplication.italian = false;}
if (Ham.isChecked()){pizzaApplication.ham=true;}
else {pizzaApplication.ham = false; }
if (Pepperoni.isChecked()){pizzaApplication.pepperoni=true;}
else {pizzaApplication.pepperoni = false;}
if (Chicken.isChecked()){pizzaApplication.chicken=true;}
else {pizzaApplication.chicken = false; }
的每行代碼,您張貼除了第一個是無效的Java代碼。而且你的班級不尊重標準的命名約定。我不明白你想要做什麼,特別是有這麼幾個代碼發佈。我的建議是購買一本好的,最近的,介紹性的Java書或閱讀Java教程。你可能尋找「什麼是對象」或「如何構造一個對象」或「什麼是構造函數」。這將在所有Java入門書籍或教程中介紹。 –
在知道了建立從一個類的對象實例化** **。您正在創建一個新的對象,它是比薩類的_instance_。我會閱讀關於如何在Java中這樣做,因爲你發佈的內容是沒有意義的。 –